Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 5 - Loops - Programming Exercises - Page 165: 5.36

Answer

code

Work Step by Step

# 5.36 (Game: scissor, rock, paper) Programming Exercise 4.17 gives a program that # plays the scissor, rock, paper game. Revise the program to let the user play continuously # until either the user or the computer wins more than two times. import random count = 0 while count <= 2 or count <= -2: # Generate scissor, rock, paper computerNumber = random.randint(0, 2) # Prompt the user to enter scissor, rock, or paper userNumber = eval(input("scissor (0), rock (1), paper (2): ")) # Check the guess if computerNumber == 0: if userNumber == 0: print("It is a draw") elif userNumber == 1: print("You won") count += 1 elif userNumber == 2: print("You lost") count -= 1 elif computerNumber == 1: if userNumber == 0: print("You lost") count -= 1 elif userNumber == 1: print("It is a draw") elif userNumber == 2: print("You won") count += 1 elif computerNumber == 2: if userNumber == 0: print("You won") count += 1 elif userNumber == 1: print("You lost") count -= 1 elif userNumber == 2: print("It is a draw") if count > 2: print("You won more than two times") else: print("The computer won more than two times")
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.