I am trying to set up a simple user-input menu (non-gui) as follows:
If the user inputs 0:
- a file is loaded.
- a menu comes up with options 1-5 prompting for another user input from 1 to 5. Now, here, after the first user input, some processing is done. Then I would like to ask the user for a second user input. This should continue until the user enters 6 or larger.
Else (if the user does not enter 0) Print "Error exiting. Please restart program."
Here is what I have:
import csv
# Load input file:
choiceloading = input('Please enter 0 to load the input file: ')
if choiceloading == 0:
with open('eggs.csv', 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in spamreader:
print ', '.join(row)
print (" M A I N - M E N U")
print ("1. Action 1")
print ("2. Action 2")
print ("3. Action 3")
print ("4. Action 4")
print ("5. Action 5")
# Get user input:
choice = raw_input('Enter choice [1-5] : ')
# Convert input (number) to int type:
choice = int(choice)
# Perform action based on menu-option selection by user:
if choice == 1:
print ("Action 1...")
#processing #1 is done here
elif choice == 2:
print ("Action 2...")
#processing #2 is done here
elif choice == 3:
print ("Action 3...")
#processing #3 is done here
elif choice == 4:
print ("Action 4...")
#processing #4 is done here
elif choice == 5:
print ("Action 5...")
#processing #5 is done here
else:
print ("Invalid entry. You should choose 1-5 only. Program exiting.....please restart it and try again.")
else:
print ("Invalid entry. You should choose 0 to load the file. Program exiting.....please restart it and try again.")
Currently, the program only accepts 1 user input. After processing, it then exits. ex. if the user enters 3, and processing of 3 is complete then the program will exit.
However, I would like to allow the user to enter 1,2,4,5 for processing of 1,2,4,5. Then they should enter >5 to exit.
Question: After processing, how can this code be changed to allow the user to enter the remaining outputs?