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, 23.06.2019 10:50
Your friend kayla is starting her own business and asks you whether she should set it up as a p2p network or as a client-server network. list three questions you might ask to kayla decide which network to use and how her answers to those questions would affect your recommendation.
Answers: 2
question
Computers and Technology, 23.06.2019 16:00
Kenny works with an it company. his company is about to launch new software in the market. he has to ensure that this new software is functional and meets all of the quality standards set up at the planning stage. which job profile is kenny likely to have? kenny is likely to have the job profile of a blank .
Answers: 2
question
Computers and Technology, 23.06.2019 19:00
This question involves a class named textfile that represents a text file. public class textfile { private string filename; private string filename; private arraylist words; // constructors not shown // postcondition: returns the number of bytes in this file public int filesize() { } // precondition: 0 < = index < words.size() // postcondition: removes numwords words from the words arraylist beginning at // index. public void deletewords(int index, int numwords) { } // precondition: 0 < = index < = words.size() // postcondition: adds elements from newwords array to words arraylist beginning // at index. pub lic voidaddwords(int index, string[] newwords) { } // other methods not shown } complete the filesize() method. the filesize() is computed in bytes. in a text file, each character in each word counts as one byte. in addition, there is a space in between each word in the words arraylist, and each of those spaces also counts as one byte. for example, suppose the words arraylist stores the following words: { mary had a little lamb; its fleece was white as snow. } the filesize() method would compute 4 + 3 + 1 + 6 + 5 + 4 + 6 + 3 + 5 + 2 + 5 as the sum of the lengths of each string in the arraylist. the value returned would be this sum plus 10, because there would also be 10 spaces in between the 11 words. complete the filesize() method below: // postcondition: returns the number of bytes in this file public int filesize() { }
Answers: 1
question
Computers and Technology, 24.06.2019 00:50
3. what is the output of the following statements? temporary object1; temporary object2("rectangle", 8.5, 5); temporary object3("circle", 6, 0); temporary object4("cylinder", 6, 3.5); cout < < fixed < < showpoint < < setprecision(2); object1.print(); object2.print(); object3.print(); object4.print(); object1.set("sphere", 4.5, 0); object1.print();
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, 27.01.2020 22:31