import random
import sys
print('Rock, Paper, Scissor')
#These variables keep track of the number of wins, losses, and ties.
wins = 0
losses = 0
ties = 0
while True:
print('%s Wins, %s Losses, %s Ties' % (wins, losses, ties))
while True:
print('Enter your move: (r)ock, (p)aper, (s)issorcs, or (q)uit.')
playerMove = input()
if playerMove == 'q':
sys.exit()
if playerMove == 'r' or playerMove == 'p' or playerMove == 's':
break
print('Type one of r, p, s, or q.')
if playerMove == 'r':
print('Rock versus...')
elif playerMove == 's':
print('Scissors versus...')
elif playerMove == 'p':
print('Paper versus...')
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')
if playerMove == computerMove:
print('Wow! It is a tie!')
ties = ties 1
elif playerMove == 'r' and computerMove == 's':
print('Rock smashes Scissors! You win!!!')
wins = wins 1
elif playerMove == 'p' and computerMove == 'r':
print('Paper smothers Rock! You win!!!')
wins = wins 1
elif playerMove == 's' and computerMove == 'p':
print('Scissors slice Paper! You win!!!')
wins = wins 1
elif playerMove == 's' and computerMove == 'r':
print('Rock smashes Scissors! You lose!!!')
lossess = losses 1
elif playerMove == 'r' and computerMove == 'p':
print('Paper smothers Rock! You lose!!!')
lossess = losses 1
elif playerMove == 'p' and computerMove == 's':
print('Scissors slice Paper! You lose!!!')
lossess = losses 1
When I run this in PyCharm it accepts my inputs(the r,s,p,or q) but doesn't move forward with the game. The only input that works correctly is q. That leads me to think I don't have the break in my while-Loop correct, but it also is not returning any errors so I don't know what's up.
Apricate any help or hints you all can give me.
CodePudding user response:
You just need to make your indentation proper by making all the code after print('Type one of r, p, s, or q.')
outside of the inner while loop.
Also, check the variable "losses".
CodePudding user response:
It is breaking loop everytime in
if playerMove == 'r' or playerMove == 'p' or playerMove == 's':
break
try like this
import random
import sys
print('Rock, Paper, Scissor')
#These variables keep track of the number of wins, losses, and ties.
wins = 0
losses = 0
ties = 0
while True:
print('%s Wins, %s Losses, %s Ties' % (wins, losses, ties))
while True:
print('Enter your move: (r)ock, (p)aper, (s)issorcs, or (q)uit.')
playerMove = input()
if playerMove == 'q':
sys.exit()
print('Type one of r, p, s, or q.')
if playerMove == 'r':
print('Rock versus...')
elif playerMove == 's':
print('Scissors versus...')
elif playerMove == 'p':
print('Paper versus...')
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')
if playerMove == computerMove:
print('Wow! It is a tie!')
ties = ties 1
elif playerMove == 'r' and computerMove == 's':
print('Rock smashes Scissors! You win!!!')
wins = wins 1
elif playerMove == 'p' and computerMove == 'r':
print('Paper smothers Rock! You win!!!')
wins = wins 1
elif playerMove == 's' and computerMove == 'p':
print('Scissors slice Paper! You win!!!')
wins = wins 1
elif playerMove == 's' and computerMove == 'r':
print('Rock smashes Scissors! You lose!!!')
lossess = losses 1
elif playerMove == 'r' and computerMove == 'p':
print('Paper smothers Rock! You lose!!!')
lossess = losses 1
elif playerMove == 'p' and computerMove == 's':
print('Scissors slice Paper! You lose!!!')
lossess = losses 1
if playerMove == 'r' or playerMove == 'p' or playerMove == 's':
break