Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 应为缩进块,无法找到位置或原因_Python - Fatal编程技术网

Python 应为缩进块,无法找到位置或原因

Python 应为缩进块,无法找到位置或原因,python,Python,我似乎不明白为什么我的程序不能运行。它一直在说,我试着回去,确保我没有缩进太多或太少,但我似乎找不到问题。有人能帮忙吗?谢谢你 import random userChoice = eval(input("Scissor (0), Rock (1), Paper (2)")) computerChoice = random.randint(0,2) if computerChoice == 0: elif computerChoice == 1: elif computerChoice ==

我似乎不明白为什么我的程序不能运行。它一直在说,我试着回去,确保我没有缩进太多或太少,但我似乎找不到问题。有人能帮忙吗?谢谢你

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!")

这些空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'
显然,用您试图做的一些实现来替换这些print语句。但那里不可能什么都没有

异常-如果确实不想执行任何操作,则可以接受pass语句

if computerChoice == 0:
    pass # do nothing here
elif computerChoice == 1:
    pass # do nothing here
elif computerChoice == 2:
    pass # do nothing here
if-elif块中缺少冒号后面的语句。您可以尝试添加pass

Python中的pass语句在需要语句时使用 但您不希望执行任何命令或代码


您有空的if/elif语句。另外,使用int而不是eval@AndrewL。嗨,安德鲁,你说我有空的if/elif语句是什么意思?我不明白。你不能有一个空的控制语句,所以如果…:如果里面没有任何语句,则无效查看第6-8行、第10-12行。我不知道if/elif需要语句的主体,因为我认为if/elif已经是语句了。对不起,我对编码很陌生。谢谢你的澄清,非常感谢。@DandyPotato:但是如果你不想在条件满足时做任何事情,为什么你会有那些if和elif语句呢?例如,如果三个条件中只有一个得到满足,你可以做一些事情,而对另外两个条件什么也不做。对所有条件使用pass是没有意义的,但它可能只适用于某些条件。@Mathias虽然在这种情况下,它可能不适用于您通知我有关命令pass的信息,但我只是尝试了一下,它可以工作:。我对编码还是相当陌生的。
computerChoice = random.randint(0,2)
if computerChoice == 0:
    pass
elif computerChoice == 1:
    pass
elif computerChoice == 2:
    pass