P a g e | 1 ISTM133P: Lesson 8 Assignment © 2021 Dr. Wayne Machuca ISTM133P: Lesson 8 Assignment Creating Lists / Program Organization – Calorie Counter Program Background: The purpose of this...

1 answer below »
I need help with these 2 python assignments that I have attached.


P a g e | 1 ISTM133P: Lesson 8 Assignment © 2021 Dr. Wayne Machuca ISTM133P: Lesson 8 Assignment Creating Lists / Program Organization – Calorie Counter Program Background: The purpose of this advanced/intermediate assignment is to demonstrate basic list functionality, and to organize the program to take advantage of functions and Pythons natural scripting ability. In this program, you will use the Calorie Counter program, which was part of your in-lesson work, and submit it for your assignment. You will be redesigning the base program, creating a number of new functions, and adding lists capability in this assignment. Note: As usual, this program can be solved in several ways. As this assignment is designed to allow the student to demonstrate a specific set of outcomes, your solution should follow these guidelines. Expansion is allowed. If you include new or unusual techniques, be sure to identify these in the code AND in the message box in Blackboard. Instructions: Main Program Design your main program as follows: while True: choice = disp_menu() if choice == "a": add_process() elif choice == "d": del_item() elif choice == "q": break disp_meal() Major Functions Create functions using the following guidelines: disp_menu() This function displays user options (a = add, d = delete, m = display meal, q = quit). Invalid data entry will result in an error message and request to re-enter. Valid data entry will be returned to the call. disp_meal() This is a no data in / no data out function which will display all items in the meal and determine item and meal calories. add_process() This function controls item data entry. Will call at least the following sub-functions: P a g e | 2 ISTM133P: Lesson 8 Assignment © 2021 Dr. Wayne Machuca input_name() This function controls the valid data entry of the item name. Item names must be 20 characters or less. On invalid entry, respond with an appropriate message and request re-entry. calc_cals(string, grams) This function determines the number of calories based on grams and element. This is called during the calorie calculation activity. You will pass each of the gram amounts to the same function. This function will receive the grams and determine whether to multiply by 4 or by 9. You will also pass the element type using the symbols “c” for carbs, “f” for fats, and “p” for proteins. The calories for that element are returned to the call. input_grams(string) This function controls data validation for the gram integer data entry. Use this same function for all three elements. add_item(string, calories) This function controls adding the item name and corresponding calories to the appropriate lists. Hint: Remember to make two lists, one for item names and one for item calories; and, define these lists globally. del_item() This function is called from the main program and controls deleting items from the meal list. During this function, provide the user with the meal list. Prompt the user to choose which item to delete based on item number. Data validation: • If there are no items in the meal, display an appropriate message and do not display the meal lists • Delete choice should be a valid integer • Delete choice must exist on the list. Do not allow the user to choose an item which does not exist. Upon valid data, verify the user’s intent with an “Are you sure…?” message. Valid entries are “y” or “n”. With an “n” entry, respond with an appropriate message such as “Item [name] was not deleted…”. With an “y” entry, execute the delete action and respond with an appropriate message such as “Item [name] was deleted…”, and then either display the current meal, or, if the meal is empty, an appropriate message. Lists Create 2 lists to control your meal menu. You may call these anything you want. For this assignment use item_list[ ] to contain the item names, and cals_list[ ] to contain the number of calories for each item. These lists must be maintained together. P a g e | 3 ISTM133P: Lesson 8 Assignment © 2021 Dr. Wayne Machuca Output While actual output solutions may vary, here is a sample output for the addition of a second item into the meal: What would you like to do? a = add an item d = delete an item m = display the meal so far q = quit make a selection>a please enter the item> banana enter grams of carbs> 2 enter grams of fats> 2 enter grams of protein> 2 total calories for banana are 34 would you like to include banana? (y/n)> y item banana entered. Meal Calorie Counter Num Item Cals --- ---- ---- 1. apple 17 2. banana 34 Your meal has 2 items for a total of 51 calories -------------------- What would you like to do? a = add an item d = delete an item m = display the meal so far q = quit make a selection> Testing This lab requires a complete redesign of your lab. For credit, you must demonstrate that all aspects of this program function appropriately. In your test proof, be sure to include: • Proper entry and functioning of valid data • Invalid data attempts on all inputs, include “fuzzy” data attempts • Demonstration of multiple entries and accumulation. Insufficient testing proof will result in a diminished score. P a g e | 4 ISTM133P: Lesson 8 Assignment © 2021 Dr. Wayne Machuca Submission Follow the instructions in the video “How to submit homework” to complete your homework solution. Complete and submit the calorie counter program only. Save this document for your records. Remember, your Python code MUST have your name and identification banner as described in the lectures. Value This assignment is worth 100 points. Notice increased lab value. Note: This document was checked for ADA Accessibility on June 15, 2020. Due to the programmatic nature of Python, portions of this document may be unintelligible to some screen readers. P a g e | 1 ISTM133P: Lesson 8 Assignment © 2021 Dr. Wayne Machuca ISTM133P: Lesson 9 Assignment Creating Lists / Program Organization – Girl Scout Cookie Program Background: The purpose of this advanced/intermediate assignment is to demonstrate 2-Dimensional List functionality, and to organize the program to take advantage of functions and Pythons natural scripting ability. In this program, you will redesign the GSC program, which was part of your in-lesson work, based upon the structural changes identified in Lesson 8. Your will thoroughly test and submit this program for your assignment. Your redesign will create a number of new functions, and add 2-dimensional lists capability. Note: As usual, this program can be solved in several ways. As this assignment is designed to allow the student to demonstrate a specific set of outcomes, your solution should follow these guidelines. Expansion is allowed. If you include new or unusual techniques, be sure to identify these in the code AND in the message box in Blackboard. Instructions: Main Program Design your main program as follows: # Primary loop choice = "" # seeding value while choice.lower() != "q": #while True: choice = disp_menu() if choice == "a": add_process() elif choice == "d": delete_process() elif choice != "q": disp_order() Lists There should be five lists for this program. • order_list – this is the 2D list for controlling the order collection • menu_list – this list contains the processing selection options and is displayed in disp_menu() • flavor_list – this list contains the names of the cookie flavors available for purchase. Flavors will be: o Savanahs, Thin-Mints, Tag-a-longs, Do-Si-Dos, PeanutButter (spelling is critical) • up_charge_list – this list contains the names of cookies which sell at $5.00 per box. All other flavors sell at $3.50 per box. Flavors will be o Tag-a-longs, PeanutButter, LemonDos P a g e | 2 ISTM133P: Lesson 8 Assignment © 2021 Dr. Wayne Machuca • detail_list – this is the 1D list containing the item selection and is input for the order_list. Fields in this list will be o choice – the cookie flavor identified by it’s index in the flavor_list o qty – the quantity of boxes ordered o price – the price per box for this flavor Major Functions Create functions using the following guidelines: disp_menu() This function displays user options (a = add, d = delete, o = display order, q = quit). Invalid data entry will result in an error message and request to re-enter. Valid data entry will be returned to the call. disp_flavors() This function displays the cookie flavors available for selection. No data is passed to or returned from this function. disp_order() This is a no data in / no data out function which will display all items in the order; and will determine the total number of boxes in the order, and the total price of the order. If there are no items in the meal to display, the program will generate an error message to that effect. add_process() This function controls item data entry and will call at least the following sub-functions: input_flavor() [subfunction of add_process] This function controls the valid data entry of the flavor. The list of flavors is displayed in disp_flavors(). Each flavor is identified by an item number which is the list index + 1. Input must be an integer and must be one of the numbers available in the list display. On valid entry, the choice value is
Answered 1 days AfterMay 24, 2021

Answer To: P a g e | 1 ISTM133P: Lesson 8 Assignment © 2021 Dr. Wayne Machuca ISTM133P: Lesson 8 Assignment...

Pratap answered on May 26 2021
161 Votes
"""
Calorie Counter Program
"""
item_names = []
item_calories = []
def disp_menu():
"""
Function to display the menu op
tions
:return: valid user input
"""
print(
'\nWhat would you like to do?',
'\na = add an item',
'\nd = delete an item',
'\nm = display the meal so far',
'\nq = quit'
)
try:
user_choice = input('make a selection> ')
if user_choice not in ['a', 'd', 'm', 'q']:
raise Exception
else:
return user_choice
except:
print('Invalid selection!')
def disp_meal():
"""
Function to display the meals entered so far
:return: None
"""
global item_names, item_calories
if len(item_names) == 0:
print('There are no items to display!')
else:
headers = ['Num', 'Item', 'Cals']
width_0 = max(len(x) for x in [str(i+1) + '.' for i in range(len(item_names)+1)] + [headers[0]]) + 2
width_1 = max(len(x) for x in item_names + [headers[1]]) + 4
width_2 = max(len(str(x)) for x in item_calories + [headers[2]]) + 4
print(
'\nMeal Calorie Counter',
'\n' + headers[0].ljust(width_0) + headers[1].ljust(width_1) + headers[2].ljust(width_2)
)
print(
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here