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 23:50
You need to design a circuit that implements the functions in the following table: s0 s1 function0 0 a + 10 1 a – b1 0 a + b1 1 a – 1s0 and s1 are 1-bit control inputs to select the function of the circuit. inputs a and b are 4-bitnumbers in 2s complement form. the output is also a 4-bit number in 2s complement form.you are allowed to use only one ttl 7483 4-bit adder to implement all the functions. but anynumber of other components (except the adder) can be used.hint: design a combinational logic circuit to modify the input b and the “carry input” of theadder depending on the control inputs s0 and s1.important: lab grade will depend on the working of the circuit & will be checked of by your labinstructor.1. is the output valid for the following input combinations: a. s0 = 0, s1 = 0, a = 7, b = 3? b. s0 = 0, s1 = 1, a = 7, b = 3? c. s0 = 1, s1 = 0, a = -4, b = -5? d. s0 = 1, s1 = 1, a = -8, b = 6? 2. what is the range of inputs (for both a and b) that will produce the valid output for all the functions?
Answers: 3
question
Computers and Technology, 23.06.2019 01:50
Write a program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: a. double the number. b. reverse the digits of the number. c. raise the number to the power of 2, 3, or 4. d. sum the digits of the number. e. if the number is a two-digit number, then raise the first digit to the power of the second digit. f. if the number is a three-digit number and the last digit is less than or equal to 4, then raise the first two digits to the power of the last digit. after performing an operation if the number is less than 10, add 10 to the number. also, after each operation determine if the number is prime. each successive operation should be performed on the number generated by the last operation. your program should not contain any global variables and each of these operations must be implemented by a separate function. also, your program should be menu driven. 7. (fraction calculator) write a program that
Answers: 1
question
Computers and Technology, 23.06.2019 11:00
Describe three characteristics of at-risk drivers. a. b. c. describe three characteristics of safe drivers. a. b. c. describe three driver errors that could cause a collision. a. b. c. how will this information affect you as a driver now and in the future? (2-3 sentences)
Answers: 2
question
Computers and Technology, 25.06.2019 11:30
Aubrey didnt like to use graphics or images on her slides. she preferred to use only a title for her slides and bullet-poinged text. what is the best thing you could say to aubrey about using media that might change her mind? a. as long as you use it responsibly, it will only enhance your slides and engage your audience. b. actually, aubrey's beliefs are well founded and backed up by research. c. you should always try to inlcude as much media as you can on a slide. d. media will keep your audience entertained and take the pressure off the presenter.
Answers: 1
You know the right answer?
Step 1:Write code that calls a function named printMenu() The printMenu() function will:
pri...
Questions
question
Mathematics, 08.04.2021 06:00
question
Mathematics, 08.04.2021 06:00
question
Mathematics, 08.04.2021 06:00
question
Mathematics, 08.04.2021 06:00
question
Mathematics, 08.04.2021 06:00
question
Mathematics, 08.04.2021 06:00
question
Mathematics, 08.04.2021 06:00
Questions on the website: 13722360