代码打印';无效输入';在';岩石剪纸机';python游戏

代码打印';无效输入';在';岩石剪纸机';python游戏,python,if-statement,input,Python,If Statement,Input,我打印了一个代码,但在您编写任何输入后,它都会显示谁赢了和“无效输入”,我不知道我做错了什么?有人能帮我吗 import random while True: user_move = str(input()) user_move = user_move.lower() choices= ['rock', 'paper', 'scissors'] computer_choice = random.choice(choices) if user_move in choices: if

我打印了一个代码,但在您编写任何输入后,它都会显示谁赢了和“无效输入”,我不知道我做错了什么?有人能帮我吗

import random
while True: 
user_move = str(input())
user_move = user_move.lower()

choices= ['rock', 'paper', 'scissors']

computer_choice = random.choice(choices)

if user_move in choices:
    if user_move == computer_choice:
        print(f'There is a draw ({user_move})')
    if user_move == 'rock':
        if computer_choice == 'paper':
            print(f'Sorry, but the computer chose {computer_choice}' )
        elif computer_choice == 'scissors':
            print(f'Well done. The computer chose {computer_choice} and failed')
    if user_move == 'paper':
        if computer_choice == 'scissors':
            print(f'Sorry, but the computer chose {computer_choice}')
        elif computer_choice == 'rock':
            print(f'Well done. The computer chose {computer_choice} and failed')
    if user_move == 'scissors':
        if computer_choice == 'rock':
            print(f'Sorry, but the computer chose {computer_choice}')
        elif computer_choice == 'paper':
            print(f'Well done. The computer chose {computer_choice} and failed')
if user_move == '!exit':
    print('Bye!')
else:
    print('Invalid input')  ```


如果用户移动==,您的
!退出“:
应该是
elif
。如果第一个
if
运行,则
else
将不会运行。

您使用了错误的if语句。在第一个if(用户\移入选项)之后,下一个不应该是if,而应该是elif。因为如果它是不真实的,计算机就会打印else代码


p、 默认情况下,s.input()是一个字符串,因此您不必编写str(input())

替换[如果用户输入='!退出:'] 使用[elif user_input=='!exit:']

进一步了解缩进和if->elif->else语句在python中的工作方式。

我已经删除了标记。该标记寻址库,但不适用于用Python编写的游戏。