预期的缩进块 - 让我疯狂
问题描述:
choice = '' #Initialise choice to blank so will enter loop
print('MAIN MENU') #---
print('-----------') #--
print('1) Encrypt a message') #- Display main menu
print('2) Decrypt a message') #--
print('3) Exit') #---
while choice not in ['1','2','3']:
choice = input('Please choose 1,2 or 3 ')#Get user's choice
if choice == "1":
#encrypt() Call encrypt function
elif choice == '2':
# decrypt() Call decrypt function
else:
sys.exit() #Exit the program
为什么发生这种情况无论我尝试什么缩进我仍然得到错误! 我已经看过其他的答复,但没有人可以帮助 - 我相信这是微不足道的,但我已经试过配置负载但没有工作预期的缩进块 - 让我疯狂
答
像if
和elif
块语句后,必须至少有一个缩线。注释不计,因此在这里没有缩进的行:
if choice == "1":
#encrypt() Call encrypt function
elif choice == '2':
# decrypt() Call decrypt function
您可以使用pass
说法,如果你不想在块做任何事情:
if choice == "1":
pass #encrypt() Call encrypt function
elif choice == '2':
pass #decrypt() Call decrypt function
+0
嗯,我已经学会了一些东西#评论不算数感谢我以为我生气了 –
答
你不能有空的,如果要不块,
while choice not in ['1','2','3']:
choice = input('Please choose 1,2 or 3 ')#Get user's choice
if choice == "1":
pass
elif choice == '2':
pass
else:
sys.exit() #Exit the program
与Pydev的精选文摘使用将有很大的帮助缩进和整体编码! –