Vi write a game of scissors and stone
Code:
Import randomprint ("if you don't want to play a game, press q to exit! ") While True: player = input (" Please input 0 scissors 1 stone 2 cloth: ") computer = random. randint (0, 2) if player = "q": print ("Bye! ") Break else: if player. isdigit (): player = int (player) if player <= 2 and player> = 0: #2. judge the user input, and then display the corresponding result if (player = 0 and computer = 2) or (player = 1 and computer = 0) or (player = 2 and computer = 1): print ("win! You can buy milk powder! ") Elif player = computer: print! Go home and get the money. Come back! ") Else: print (" the input number is out of the range! ") Continue else: print (" input error! ") Continue
Thoughts:
In a simple stone scissors game, the input error has not been determined at the beginning, for example, if the user does not enter an integer at the beginning, and the range is determined when the input is an integer. This mini-game is improved by adding the if judgment statement to exclude user input errors. If you are interested, you can take it and relax.★