Recently I started programming with python. Today I was trying to make a stone, paper, scissor game. After so scratching my head long time, Finallyfinally I got a working code.
from random import choice
from random import choice
def play_again():
print "Do you want to play again:- Choose 'yay' or 'nay'"
user_again = raw_input('->')
if user_again == 'yay':
SPCa()
elif user_again == 'nay':
print "Ok bye! hope you enjoyed the game. See you soon! :)"
else:
print "Please choose correct option."
play_again()
def SPCa():
computer_choice = choice( ['stone', 'paper', 'scissor'] )
computer_choosed = "Computer choosed %s" % computer_choice
print "Make an choice"
print "Choose stone, paper, scissor"
user_choice = raw_input('->')
if user_choice == computer_choice:
print computer_choosed
print "So it's a tie"
play_again()
elif user_choice == 'stone':
if computer_choice == 'paper':
print computer_choosed
print "So, You loose"
play_again()
elif computer_choice == 'scissor':
print computer_choosed
print "So, Cheers! You won!"
play_again()
elif user_choice == 'paper':
if computer_choice == 'scissor':
print computer_choosed
print "So, you loose."
play_again()
elif computer_choice == 'stone':
print computer_choosed
print "So, Cheers! You won!"
play_again()
elif user_choice == 'scissor':
if computer_choice == 'stone':
print computer_choosed
print "So, you loose."
play_again()
elif computer_choice == 'paper':
print computer_choosed
print "So, Cheers! You won!"
play_again()
else:
print "please choose correct option"
SPCa()
def SPC():
computer_choice = choice( ['stone', 'paper', 'scissor'] )
computer_choosed = "Computer choosed %s" % computer_choice
print "You are playing Stone, Paper, Scissor."
print "Make an choice"
print "Choose stone, paper, scissor"
user_choice = raw_input('->')
if user_choice == computer_choice:
print computer_choosed
print "So it's a tie"
play_again()
elif user_choice == 'stone':
if computer_choice == 'paper':
print computer_choosed
print "So, You loose"
play_again()
elif computer_choice == 'scissor':
print computer_choosed
print "So, Cheers! You won!"
play_again()
elif user_choice == 'paper':
if computer_choice == 'scissor':
print computer_choosed
print "So, you loose."
play_again()
elif computer_choice == 'stone':
print computer_choosed
print "So, Cheers! You won!"
play_again()
elif user_choice == 'scissor':
if computer_choice == 'stone':
print computer_choosed
print "So, you loose."
play_again()
elif computer_choice == 'paper':
print computer_choosed
print "So, Cheers! You won!"
play_again()
else:
print "please choose correct option"
SPCa()
SPC()
But I found my code so repetitive, it has not even a single a loop. Please suggest how can I improve my code. What are things that iI should learn?