Question: Adjust the program from Hands-on 6 RPS I. Add a loop to enforce that the user inputs a valid entry of 1 for Rock, 2
Adjust the program from Hands-on 6 RPS I.
Add a loop to enforce that the user inputs a valid entry of 1 for Rock, 2 for Paper or 3 for Scissors.
Add another loop keep playing until either the computer or user gets 5 wins. In that loop keep track how many times computer wins, user wins and tied games. Display the count at after the loop ends.
Write the code and upload to canvas. Upload the output from instances of the 3 scenarios (invalid entry, computer wins 5 and user wins 5 games) from your running program.
Hands-on 6 RPS I input coding :
import random
def chooseoption():
userchoice=int(input('Enter 1 for Rock,2 For Paper,3 for Scissors :'))
if userchoice == 1:
userchoice='Rock'
elif userchoice == 2:
userchoice='Paper'
elif userchoice == 3:
userchoice='Scissors'
else:
print("Please try again")
chooseoption()
return userchoice
def computeroption():
computerchoice=random.randint(1,3)
if computerchoice==1:
computerchoice='Rock'
elif computerchoice==2:
computerchoice='Paper'
else:
computerchoice='Scissors'
return computerchoice
while True:
userchoice=chooseoption()
computerchoice=computeroption()
print('Your choose '+userchoice)
print('The Computer choose '+computerchoice)
if userchoice=='Rock':
if computerchoice=='Rock':
print("You tied.Try again")
elif computerchoice=='Paper':
print("You Lost.Try Again")
elif computerchoice=='Scissors':
print("Congrts, you won ! Good bye.")
break
elif userchoice=='Paper':
if computerchoice=='Rock':
print("Congrts, you won ! Good bye.")
break
elif computerchoice=='Paper':
print("You tied.Try again")
elif computerchoice=='Scissors':
print("You Lost.Try Again")
elif userchoice=='Scissors':
if computerchoice=='Rock':
print("You Lost.Try Again")
elif computerchoice=='Paper':
print("Congrts, you won ! Good bye.")
break
elif computerchoice=='Scissors':
print("You tied.Try again")
Output :
Enter 1 for Rock, 2 for Paper, 3 for Scissors: 2
You chose paper
The computer chose scissors
You lost. Try again!
Enter 1 for Rock, 2 for Paper, 3 for Scissors: 1
You chose rock
The computer chose rock
You tied. Try again!
Enter 1 for Rock, 2 for Paper, 3 for Scissors: 3
You chose scissors
The computer chose paper
Congrats, you won! Good bye.
Step by Step Solution
3.36 Rating (140 Votes )
There are 3 Steps involved in it
import random def chooseoption while True userchoice inputEnter 1 for Rock 2 For Paper 3 for Scissor... View full answer
Get step-by-step solutions from verified subject matter experts
