subject

Step 1:Write code that calls a function named printMenu() The printMenu() function will:
print the menu below
ask the user to input a value between 1 an 12
return an integer value to your main program.
In the main part of your program print the value entered by the user. Use a print statement that is appropriate, not simply a print statement with the value.
Completed:
def myMenu(numArg):
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')
choice = int(input('Enter a number between 1 and 12:'))
return choice
# Main code
somenum = 10
myInput = myMenu(somenum)
print('The user entered: choice:', myInput)
Stage 2 (done)
Keep the following requirements from Stage #1
Write code that calls a function named printMenu()
The printMenu() function will:
print the menu below
ask the user to input a value between 1 an 12
return an integer value to your main program.
Within the printMenu() function:
I STRONGLY SUGGEST THAT YOU DO THESE ONE AT A TIME - get the loop working before you move to the next one - get the check working before you add the try/except
Add a loop to allow the user to continue to enter input until they enter a value between 1 and 12
Add code to catch input values less than 1 and greater than 12
Add a try/except block to catch a ValueError if the user inputs an alphabetic character/string
Create a function named processInput()
Pass a single argument to the function - this will be the value returned from the printMenu() function
The processInput() function will simply print the value of the argument passed in.
Use a different variable name in your main code and in your function

Completed:

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')

def processInput(choice):
print('The user entered choice: ',choice)

def printMenu():
while True:
try:
myMenu()
choice = int(input('Enter a number between 1 and 12. '))
if choice > 12:
print('Enter a number between 1 and 12. ')
else:
return choice
except ValueError:
print('Invalid number enter.')

def main():
choice=printMenu()
processInput(choice)

main()

Stage 3 (help!)
Keep all of the requirements from Stage #2
Within the processInput() 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.

At the TOP of you main code you need to place your code that read the file

The code to read and prepare this file is below

#Global variable
data = []

# Open the data file
infile = open("Mac_menu. csv", "r")

# Read the header line
line = infile. readline()

# Read each line of the file
for line in infile:

# strip the '\n' character
line = line. rstrip("\n")
# Split the line of input on the commas
# THEN create a tuple from those elements
result = tuple(line. split(","))
# Append the tuple onto the list named 'data'
data. append(result)

infile. close()

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 03:40
Mary's manager told her she should insert a graphic into her documentwrite mary a brief note describing how to insert a graphicin a word processing document.
Answers: 1
question
Computers and Technology, 22.06.2019 10:50
Using least squares fitting, you are to fit the data sets to the following models and solve for the parameters ai , where i is the index of the parameter. the input/output data for the systems are linked in the bblearn site. for each of the systems use matlab to plot the supplied data vs. the model fit on one plot. include your code in the solutions. (a) linear fit "lineardata.mat" y=a1x^3 + a2x^2 + a3x + a4 (b) plant fit "plantdata.mat g(s) = a1/(s + a2)
Answers: 1
question
Computers and Technology, 23.06.2019 01:30
Which tab is used to change the theme of a photo album slide show? a. design b. view c. transitions d. home
Answers: 1
question
Computers and Technology, 23.06.2019 09:10
(328 inc. 448 ind. 480 in25. john has a collection of toy cars. he has 2 red cars, 4 blue cars, 4 black cars, and 6 yellowcars. what is the ratio of red cars to yellow cars? a. 1: 2b. 1: 3c. 1: 626. the net of a right triangular prism is shown below.
Answers: 2
You know the right answer?
Step 1:Write code that calls a function named printMenu() The printMenu() function will:
pri...
Questions
question
Mathematics, 25.08.2021 02:50
question
Mathematics, 25.08.2021 02:50
question
Mathematics, 25.08.2021 02:50
question
History, 25.08.2021 02:50
Questions on the website: 13722363