缩进错误但不明白为什么?
问题描述:
我写了一个python程序,当我说它时,它说有一个IndentationError,我知道它是什么,但不明白为什么。一切似乎都合法:/缩进错误但不明白为什么?
# encoding : utf-8
from math import *
def menu():
print("""
Choisissez parmi ces actions :
[1] Afficher un vecteur donné par deux points
[2] Afficher le résultat de l'addition ou de la soustraction de deux vecteurs
[3] Afficher le résultat de la multiplication d'un vecteur par un nombre
[4] Afficher le produit scalaire de deux vecteurs de R2 ou de R3
[5] Afficher le produit vectoriel de deux vecteurs de R3
[6] Afficher la norme d'un vecteur
[7] Afficher la normalisation d'un vecteur
[8] Afficher le projeté orthogonal d'un vecteur sur un autre
[9] Afficher l'angle (compris entre 0° et 180°) entre deux vecteurs
[10] Afficher si un vecteur est unitaire ou non
[11] Afficher si deux vecteurs sont colinéaires ou non
[12] Afficher si deux vecteurs sont orthogonaux ou non
[0] Quitter le programme
""")
choice =input()
if choice == "1":
print("Entrez votre vecteur sous la forme d'une liste : ")
vector = eval(input("Vecteur"))
print(vector)
elif choice == "2":
elif choice == "3":
#it says that the line just above contains an error
elif choice == "4":
elif choice == "5":
elif choice == "6":
elif choice == "7":
elif choice == "8":
elif choice == "9":
elif choice == "10":
elif choice == "11":
elif choice == "12":
elif choice == "0":
return None
不介意法国部分,这不重要。重要的部分是elif
函数。
PS:我使用Python 6个月以来,所以我知道我在做什么,但我不是一个亲
感谢:d
答
你不能写这样的:
elif choice == "2":
elif choice == "3":
这就提出了IndentationError
例外,所以如果你想以后实施您可以使用pass statement
,如下所示:
elif choice == "2":
pass
elif choice == "3":
pass
从pass
文档:
pass语句不做任何事情。当语句需要语法上的 时可以使用它,但该程序不需要任何操作。
答
你不能走低于一些“:”空白。
如果你不想做任何事情,然后写:
elif choice == "2":
pass
什么计划放在这些'elif' ** _语句_ **中? –
'elif'块需要一些内容。如果你现在不想做任何事情(在开发过程中)至少要添加'pass'。 – Matthias
'pass'具有什么功能? @Matthias – Blaxou