【发布时间】:2022-02-13 17:09:09
【问题描述】:
随机导入
def rpc(): a = [“石头”、“纸”、“剪刀”]
b = random.choice(a)
print(b)
userinput = input('please type rock, paper or scissor:')
if userinput == "":
print("please print the right thing")
rpc()
if userinput != "rock":
print("type the right thing!")
rpc()
if userinput != "paper":
print("type the right thing!")
rpc()
if userinput != "scissor":
print("type the right thing!")
rpc()
while b == userinput:
print("it is a draw, do you want to play another one?")
c = input("type 'y' if you want to play one more time or press 'n': ")
if c == 'y':
rpc()
elif c =='n':
break
else:
print("print the right words please")
if b == 'rock' and userinput == 'paper':
print("you win!")
rpc()
elif b == 'rock' and userinput == 'scissor':
print("you lost")
rpc()
elif b == 'paper' and userinput == 'scissor':
print("you win!")
rpc()
elif b == 'paper' and userinput == 'rock':
print("you lost!")
rpc()
elif b == 'scissor' and userinput == 'rock':
print("you win!")
rpc()
elif b == 'scissor' and userinput == 'paper':
print("you lost!")
rpc()
rpc()
这是我的石头剪刀布代码,它非常简单,但是当我运行我的代码并输入石头剪刀布时,我得到了请打印正确的东西声明,我不知道它为什么会发生,任何帮助太好了,谢谢!
【问题讨论】:
-
不直接相关:适当地命名您的变量。这可能会花费您几毫秒的打字时间,但它会节省您思考代码的时间。
-
并将您的代码拆分为逻辑片段。在这里你可以有一个
game()函数、一个ask_move()函数、一个compute_winer()函数和一个show_result()函数。虚构的例子,但你明白了重点:每个功能都应该专注于一个容易推理的事情。 -
当您修复所有其他问题时,您会遇到最大深度递归错误:一个了解此网站名称含义的机会
标签: python