python - 石头剪刀布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()
这是我的石头剪刀布代码,它非常简单,但是当我运行我的代码并输入石头剪刀布时,我得到了我的请打印正确的事情声明,我不知道它为什么会发生,任何帮助都会很棒, 谢谢你!
解决方案
让我们清理一下......
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....
推荐阅读
- marklogic - 在受管版本的文档中需要额外的数据
- html - 鼠标悬停时图像移动
- java - 如何在测试中更改 if 和 for 断言
- javascript - 如何使用 Jquery 在 mouseleave 函数下正确插入单击事件
- azure - 在 Azure 中配置和触发自动化测试环境
- swift - UIScrollView (+MessageKit/Twilio) 像 WhatsApp 一样在 scrollView 接近顶部时加载消息(乐观加载)
- python - Python:集群入门
- json - 使用 Curl 解析 json 并获取多个值
- java - 如何从循环外的请求属性中获取值
- apache - React Router 与 Apache2 + PHP7 + MariaDB docker