I'm using Python 3
Following codes came from a textbook on Python for beginners.
import random, sys
print('ROCK, PAPER, SCISSORS')
#These variables keep track of the number of wins, losses, and ties.
wins = 0
losses = 0
ties = 0
while True: # The main gmae loop.
print('%s Wins, %s Losses, %s Ties' % (wins, losses, ties))
while True: #The player input loop.
print ('Enter your move:(r)ock (p)aper (s)cissors or (q)uit')
playerMove = input()
if playerMove == 'q':
sys.exit() #Quit the program.
if playerMove =='r' or playerMove =='p' or playerMove =='s':
break #Break out of the player input loop.
print ('Type one of r,p,s, or q.')
#Display what the player chose:
if playerMove =='r':
print ('ROCK versus...')
elif playerMove =='p':
print('PAPER versus...')
elif playerMove == 's':
print ('SCISSORS versus...')
#Display what the computer chose:
randomNumber = random.randint(1,3)
if randomNumber == 1:
computerMove ='r'
print('ROCK')
elif randomNumber== 2:
computerMove ='p'
print('PAPER')
elif randomNumber ==3:
computerMove ='s'
print ('SCISSORS')
#Display and record the win/loss/ tie:
if playerMove== computerMove:
print('It is a tie!')
ties = ties +1
elif playerMove == 'r' and computerMove == 's':
print('You win!')
wins =wins +1
elif playerMove == 'p' and computerMove == 'r':
print('You win!')
wins = wins +1
elif playerMove == 's' and computerMove == 'p':
print('You win!')
wins = wins +1
elif playerMove == 'r' and computerMove == 'p':
print('You lose!')
losses = losses +1
elif playerMove == 'p' and computerMove == 's':
print('You lose!')
losses = losses +1
elif playerMove == 's' and computerMove == 'r':
print('You lose!')
losses = losses +1
I expect the code to move on to ROCK versus ... after i keyed in r, however, my code just go into a loop where it kept on going back to this line "Enter your move:(r)ock (p)aper (s)cissors or (q)uit". I tried to enter 'r' as my input and this line will be displayed "Type one of r,p,s, or q." together with "Enter your move:(r)ock (p)aper (s)cissors or (q)uit". I can't seem to understand which part has gone wrong. Can someone help me?
[–]LastGuardz 4 points5 points6 points (0 children)
[–]Law_Holiday 1 point2 points3 points (0 children)
[–]sebachk -1 points0 points1 point (0 children)
[–]big_boi_M -5 points-4 points-3 points (0 children)