当我运行程序时:
R,S or P? Rock you threw : R your enemy threw : R >>>
最后一行代码没有出现
if user_choice == computer_choice :
print ("tie!")
你知道我该怎么做吗?你知道吗
谢谢你!你知道吗
import random
def main():
user_choice = input("R,S or P?\n")
user_choice = user_choice.lower()
if user_choice == "rock" or user_choice == "r" :
print("you got R")
elif user_choice == "p" or user_choice == "paper" :
print("you got P")
elif user_choice == "s" or user_choice == "scissors" :
print("you got S")
else :
print ("wrong answer!")
computer_choice = random.randint(1,3)
if computer_choice == 1 :
print("your enemy chose R")
elif computer_choice == 2 :
print("your enemy chose P")
else :
print("your enemy chose S")
if user_choice == computer_choice :
print ("tie!")
main ()
用户选择是字符串,计算机选择是整数,所以比较总是失败的。你知道吗
更改自:
收件人:
相关问题 更多 >
编程相关推荐