The following is a part of code RockPaperScissors, I can't figure out how Python, interpret
if answer in ("y", "yes", "Y", "Yes", "Of course"):
return answer
since this return as a True.
and this other part of code below returns an Integer
player = int(player)
if player in (1, 2, 3):
return player
How is it possible that it returns True for one part and an Integer in otherpart since it is the same structure?
based on the code below:
def start():
print "Let's play a game of Rock, Paper, Scissors"
while game():
pass
scores()
def game():
player = move()
computer = random.randint(1, 3)
result(player, computer)
return play_again()
def move():
while True:
print
player = raw_input("Rock = 1\nPaper = 2\nScissors = 3\nMake a move : ")
try:
player = int(player)
if player in (1, 2, 3):
return player
except ValueError:
print "Oops ! I didn't understand that, Please enter 1, 2 or 3."
def result(player, computer):
print "1..."
time.sleep(1)
print "2..."
time.sleep(1)
print "3 !"
time.sleep(0.5)
print "Computer threw {0}!".format(names[computer])
global player_score, computer_score
if player == computer:
print "Tie game"
else:
if rules[player] == computer:
print "victory getting closer !"
player_score += 1
def play_again():
answer = raw_input("Would you like to play again ?")
if answer in ("y", "yes", "Y", "Yes", "Of course"):
return True
else:
print "ok that's enough for today !"
def scores():
global player_score, computer_score
print "HIGH SCORES"
print "Player : " + player_score
print "Computer :" + computer_score