Reputation: 69
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
Why is this happening no matter what indentation I try I still get the error! I have looked at other responses but none seem to help - I am sure it is trivial but I have tried loads of configurations but none work
Upvotes: 2
Views: 55
Reputation: 3741
You can't have empty if or else block,
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
Upvotes: 3
Reputation: 110118
After a block statement like if
and elif
, you must have at least one indented line. Comments do not count, so there are no indented lines here:
if choice == "1":
#encrypt() Call encrypt function
elif choice == '2':
# decrypt() Call decrypt function
You can use a pass
statement if you don't want to do anything in the block:
if choice == "1":
pass #encrypt() Call encrypt function
elif choice == '2':
pass #decrypt() Call decrypt function
Upvotes: 5