首页 > 解决方案 > 石头剪刀布python程序输入错误

问题描述

随机导入

def rpc(): a = ["rock", "paper", "scissor"]

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()

这是我的石头剪刀布代码,它非常简单,但是当我运行我的代码并输入石头剪刀布时,我得到了我的请打印正确的事情声明,我不知道它为什么会发生,任何帮助都会很棒, 谢谢你!

标签: python

解决方案


让我们清理一下......

userinput = input('please type rock, paper or scissor:')
while userinput not in acceptable_inputs:
    userinput = input('please type rock, paper or scissor:')
opponents_choice = random.choice(objects)
# Check and print. Loop to keep playing - 2 out of 3 wins....

推荐阅读