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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:30, jcazares3558
Awell-diversified portfolio needs about 20-25 stocks from different categories.
Answers: 2
image
Computers and Technology, 23.06.2019 13:00, torresnoemi899
Which of the following statements is false? a. a class can directly inherit from class object. b. if the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. c. a class's instance variables are normally declared private to enforce good software engineering. d. it's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.
Answers: 3
image
Computers and Technology, 23.06.2019 23:30, econsta3
Perform an online search about the booting process of a computer and list all the steps
Answers: 2
image
Computers and Technology, 24.06.2019 00:30, sethhdoty
Use the keyword strategy to remember the meaning of the following word. the meaning for the word has been provided. write your keyword and describe the picture you would create in your mind. obfuscate: to make something so confusing that it is difficult to understand.
Answers: 2
You know the right answer?
Step 1:Write code that calls a function named printMenu() The printMenu() function will:
pri...

Questions in other subjects:

Konu
Mathematics, 05.01.2021 19:20
Konu
Biology, 05.01.2021 19:20
Konu
English, 05.01.2021 19:20