Having trouble with making a 'Best of" Paper, Scissors, Rock game.
Hi All.
I have been having issues with the loop in this. I have made a game of Paper, scissors rock against the computer. My next task is to input a best of (number of games) against the computer but I can't seem to figure it out.
import random
num_games = int(input("Best of: "))
count = 0
player_wins = 0
cpu_wins = 0
def get_computer_move():
"""Deterministic 'random' move chooser"""
options = ['rock', 'paper', 'scissors']
return options[random.randint(0, 2)]
def game_result(move1, move2):
"""Rock, Paper, Scissors"""
rck = "rock"
sciss = "scissors"
pap = "paper"
if str(move1) == pap and str(move2) == rck or str(move1) == rck and str(move2) == sciss:
return 1
elif str(move1) == sciss and str(move2) == pap:
return 1
elif str(move1) == pap and str(move2) == sciss or str(move1) == rck and str(move2) == pap:
return 2
elif str(move1) == sciss and str(move2) == rck:
return 2
else:
return 0
def main():
"""Runs multipel games of PSR"""
print("Let's Play Paper, Scissors, Rock!""")
move1 = input("Make a move: ")
move1 = str.lower(move1)
move2 = get_computer_move()
print("The computer played " + move2)
game_result(move1, move2)
while game_result(move1, move2) == 0:
print("Same move entered!")
count += 1
move1 = input("Make a move: ")
move1 = str.lower(move1)
move2 = get_computer_move()
print("The computer played " + move2)
if game_result(move1, move2) == 1:
print("You win")
player_wins += 1
count += 1
if ghttps://pastebin.com/xL1tLLgwame_result(move1, move2) == 2:
print("You lose")
cpu_wins += 1
count += 1
main()
Posted May 4, 2022, 2:01 AM UTC · edited
111