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
等 block 语句之后,您必须至少有一个缩进行。评论不算在内,所以这里没有缩进:
if choice == "1":
#encrypt() Call encrypt function
elif choice == '2':
# decrypt() Call decrypt function
如果你不想在 block 中做任何事情,你可以使用一个pass
语句:
if choice == "1":
pass #encrypt() Call encrypt function
elif choice == '2':
pass #decrypt() Call decrypt function
关于python - 期待一个缩进 block - 让我发疯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35696152/