我似乎无法弄清楚为什么我的程序不会运行。它一直在说预期一个缩进的块我尝试回去确保我没有缩进太多次或太少但我似乎无法找到问题。有人可以帮忙吗?拜托,谢谢你。
import random
userChoice = eval(input("Scissor (0), Rock (1), Paper (2)"))
computerChoice = random.randint(0,2)
if computerChoice == 0:
elif computerChoice == 1:
elif computerChoice == 2:
if userChoice == 0:
elif userChoice == 1:
elif userChoice == 2:
if userChoice == 0 and computerChoice == 0:
print("The computer is Scissors. You are Scissors. It's a tie!")
elif userChoice == 0 and computerChoice == 1:
print("The computer is Rock. You are Scissors. You lost")
elif userChoice == 0 and computerChoice == 2:
print("The computer is Paper. You are Scissors. You won!")
if userChoice == 1 and computerChoice == 0:
print("The computer is Scissors. You are Rock. You won!")
elif userChoice == 1 and computerChoice == 1:
print("The computer is Rock. You are Rock. It's a tie!")
elif userChoice == 1 and computerChoice == 2:
print("The computer is Paper. You are Rock. You lost")
if userChoice == 2 and computerChoice == 0:
print("The computer is Scissors. You are Paper. You lost")
elif userChoice == 2 and computerChoice == 1:
print("The computer is Rock. You are Paper. You won!")
elif userChoice == 2 and computerChoice == 2:
print("The computer is Paper. You are Paper. It's a tie!")
答案 0 :(得分:0)
对于那些空的if / elif语句
,需要有一个正文示例(python 2样式):
if computerChoice == 0:
print 'Something needs to be done here'
elif computerChoice == 1:
print 'Something needs to be done here too'
elif computerChoice == 2:
print 'And something needs to be done here, too'
显然用一些你想要做的实现替换那些打印语句。但那里不可能有任何东西。
例外 - 如果您真的不想做任何事情,传递语句是可以接受的。
if computerChoice == 0:
pass # do nothing here
elif computerChoice == 1:
pass # do nothing here
elif computerChoice == 2:
pass # do nothing here
答案 1 :(得分:0)
if-elif块中缺少冒号:
之后的语句。您可以尝试添加pass
。
当需要语句时,使用Python中的pass语句 语法上但你不希望任何命令或代码执行。
computerChoice = random.randint(0,2)
if computerChoice == 0:
pass
elif computerChoice == 1:
pass
elif computerChoice == 2:
pass