Python Help

this is my code and im missing if statements and how to loop it back when the user inputs wrong. please help. thanks

data = []
# Open the data file
infile = open('Mac_menu.csv', 'r')

#defined Menu lists
def myMenu():
print('t1) – Category')
print('t2) – Item')
print('t3) – Serving Size')
print('t4) – Calories')
print('t5) – Calories from Fat')
print('t6) – Total Fat')
print('t7) – Cholestrol')
print('t8) – Sodium')
print('t9) – Carbs')
print('t10) – Protein')
print('t11) – Sugar')
print('t12) – Done')

#main code here
def processInput(choice):
# Create a list named headings[] the headings list should contain all the Headings from the menu
# so you have all 11 elements in the list from your menu.
headings=['Category','Item','Serving Size','Calories','Calories from Fat','Total Fat','Cholestrol',
'Sodium','Carbs','Protein','Sugar']
count=0
print('The user entered choice: {0} – {1}'.format(choice,headings[choice-1]))
for item in range (5):

sortData = sorted(data, key = lambda r:(r[choice]), reverse = True)

  

print(” {}| {} {}”.format(count+1, sortData[count][1], sortData[count][choice]))

  
count +=1
def printMenu():
while True:
try:
myMenu()
choice = int(input('Enter a number or a digit between 1 and 12. '))
if choice > 12 :
print('Enter a number or a digit between 1 and 12. ')
elif choice
print ('Error, Please write a a number or a digit between 1 and 12 ')
else:
return choice
except ValueError:
print('Invalid number entered. Please enter a digit from between 1 and 12')

def main():
choice=printMenu()
processInput(choice)
# Read the header line here
line = infile.readline()

# Read each line of the file
for line in infile:
  
# striping characters
  
line = line.rstrip('n')
  
# Split the line of input on the commas, split lines will be in tuple
  
result = tuple(line.split(','))
  
# Append the tuple
data.append(result)

  
infile.close()
main()

In Stage #2 here are the requirements: Keep all of the requirements from Stage #1

Create a function named processInput() Pass a single argument to the function – this will be the value returned from the printMenu() function Use a different variable name in your main code and in your function Create a list named headings[] the headings list should contain all the Headings from the menu except 'Quit'…so you have all 11 elements in the list from your menu. Using the value that is passed into the processInput() function print not only the numerical value of that argument – but also print the proper item from the headings[] list. This video discusses the following code

At the TOP of your main code you need to place your code that reads the file Here is the Mac_menu.csv file

Add code that will: read the file – NOTE: it has a header line Strip off the trailing 'n' character Split the line on the comma this split line should be put into a tuple append the tuple to an array

In Stage #3 here are the requirements: Keep all of the requirements from Stage #2 Within the processInput() function: Add the following code – make the necessary changes to match-up with your variable names.

The first line of code actually does the sorting for you. Let me explain a few things: data – this is the list variable you used to store all your tuples into during your file read…MAKE SURE THIS VARIABLE NAME AGREES WITH YOUR CODE. results – this is the variable that you should have passed into the processInput() function as an argument. key = lambda… – this is something we don't have time to go into but is a powerful concept of Python. reverse = True – forces it to sort from largest to smallest sortData = sorted(data, key = lambda r:(int(r[results])), reverse = True) print(” {}| {} {}”.format(count+1, sortData[count][1], sortData[count][results]))

HOWEVER – you MUST print the top 5 values from the sorted list….how are you gonna do that?

Also:

There are a some additional requirements: You can NOT sort on 'int' for the first 3 items For menu items 7 – 11, add 5 to your value. MAKE sure your function definitions are all located ABOVE your main code Make sure you add a loop that will continue to ask the user for an input value until the user enters '12' Ensure that your code works for menu items 1-3 as well as 4-6, and 7-11, and 12 Items 1, 2, and 3 are strings NOT integers, you must adjust your sort statement. Items 7 thru 11 are actually 4 off of the actual data – so if user enters 7 (cholesterol) , then you need to add 4 to the value entered from the menu BEFORE you sort. User enters 8 or 9 or 10 or 11 – same thing, add 4.

You can test your code – below are two input values and the output you should see. Enter a value 4 Top 5 Items Based On Calories: 1| “Chicken McNuggets (40 piece)” 1880 2| “Big Breakfast with Hotcakes (Large Biscuit)” 1150 3| “Big Breakfast with Hotcakes (Regular Biscuit)” 1090 4| “Big Breakfast with Hotcakes and Egg Whites (Large Biscuit)” 1050 5| “Big Breakfast with Hotcakes and Egg Whites (Regular Biscuit)” 990 Enter a value 7 Top 5 Items Based On Cholesterol : 1| “Big Breakfast with Hotcakes (Regular Biscuit)” 575 2| “Big Breakfast with Hotcakes (Large Biscuit)” 575 3| “Big Breakfast (Regular Biscuit)” 555 4| “Big Breakfast (Large Biscuit)” 555 5| “Steak & Egg McMuffin” 300

the file is too big but this is the link you can paste and search
https://docs.google.com/spreadsheets/d/1xNsI_sN1490bhsbiAbDEO3UZk_gDz3BMLR5jhiK7bds/edit?usp=sharing

please specify what info im missing, so i can give it to you guys ASAP

"Get 15% discount on your first 3 orders with us"
Use the following coupon
"FIRST15"

Order Now