Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your lab submission should consist of a single Python file, Lab5.py, uploaded to the Lab 5 Assignment folder. The Lab5.py file should meet all of

Your lab submission should consist of a single Python file, Lab5.py, uploaded to the Lab 5 Assignment folder. The Lab5.py file should meet all of the following requirements:

Your name given as the author.

Comments including a brief description of the program, Input List and Output List, and full pseudocode. Place the pseudocode for each module above the module's Python code.

The program must have at least one input and at least one output.

All user input must be validated. This means the user is not allowed to just enter any value. You must check the value, and ask the user to enter it again, and repeat this loop until the user enters a valid value.

Your program must use at least two arrays in meaningful ways. These two arrays can contain any type of values, as long as they are both used meaningfully in your program.

Your program must have at least one loop that accesses the data in the arrays. For example, you might have an input loop that asks the user to enter the data one element at a time (be sure to validate the data). Or, you might have an output loop that writes the data to the console. Or, you might have a calculation loop that calculates one or more values, such as minimum value, maximum value, averages, and so on. You can have all three of those types of loops, if you want (the Lab 5 walkthrough video shows an example of each).

Your program should be organized into separate modules. Each module should be "cohesive" and should only do one thing.

Use parameters and arguments to pass values into your modules (don't use global variables).

The Python code should run correctly, and the logic should match your pseudocode.

Below is an example of the project. I need to make a project that is similar but not an exact copy. Can be on any recipe or type of process

 __author__ = ''  # Input List: names, volumes, proofs # Output List: names, volumes, proofs, total_volume, total_volume_alcohol, percent_ingredient, percent_alcohol, counter  # Constant Integer MAX_INGREDIENTS = 256  MAX_INGREDIENTS = 256 # Function String get_string(String prompt) # Declare String value # # Display prompt # Input value # return value # End Function  def get_string(prompt): value = ""   value = input(prompt) return value # Function Real get_real(String prompt) # Declare String value # # Display prompt # Input value # While not value is a real number # Display value, "is not a number. Please try again." # Display prompt # Input value # End While # Return value # End Function  def valid_real(value): try: float(value) return True except: return False def get_real(prompt): value = ""   value = input(prompt) while not valid_real(value): print(value, "is not a number. Please try again.") value = input(prompt) return float(value) # Function Boolean y_or_n(String prompt) # Declare String value # # Display prompt # Input value # While True # If value == "Y" Or value == "y" Then # Return True # Else If value == "N" Or value == "n" Then # Return False # Else # Display "Please enter Y or N!" # Display prompt # Input value # End If # End While # End Function  def y_or_n(prompt): value = ""   value = input(prompt) while True: if value == "Y" or value == "y": return True elif value == "N" or value == "n": return False else: print("Please enter Y or N!") value = input(prompt) # Function Integer get_ingredients(String[] names, Real[] volumes, Real[] proofs) # Declare Boolean done = False # Declare Integer counter = 0 # # While not done # names[counter] = get_string("What is the name of the ingredient? ") # volumes[counter] = get_real("How much " + names[counter] + " do you want? ") # proofs[counter] = get_real("What proof is " + names[counter] + "? ") # counter = counter + 1 # done = y_or_n("Are you finished entering ingredients (Y/N)? ") # End While # Return counter # End Function  def get_ingredients(names, volumes, proofs): done = False counter = 0 while not done: names[counter] = get_string("What is the name of the ingredient? ") volumes[counter] = get_real("How much " + names[counter] + " do you want? ") proofs[counter] = get_real("What proof is " + names[counter] + "? ") counter = counter + 1 done = y_or_n("Are you finshed entering ingredients (Y/N)? ") return counter # Function Real, Real calculate_totals(Integer number_of_ingredients, Real[] volumes, Real[] proofs) # Declare Integer counter = 0 # Declare Real total_volume = 0.0 # Declare Real total_volume_alcohol = 0.0 # # While counter < number_of_ingredients # total_volume = total_volume + volumes[counter] # total_volume_alcohol = total_volume_alcohol + volumes[counter] * proof[counter] / 200.0 # counter = counter + 1 # End While # Return total_volume, total_volume_alcohol # End Function  def calculate_totals(number_of_ingredients, volumes, proofs): counter = 0 total_volume = 0.0 total_volume_alcohol = 0.0 while counter < number_of_ingredients: total_volume = total_volume + volumes[counter] total_volume_alcohol = total_volume_alcohol + volumes[counter] * proofs[counter] / 200.0 counter = counter + 1 return total_volume, total_volume_alcohol # Module display_recipe(Integer number_of_ingredients, String[] names, Real[] volumes, Real[] proofs, # Real total_volume, Real total_volume_alcohol) # Declare Integer counter = 0 # Declare Real percent_alcohol # Declare Real percent_ingredient # # While counter < number_of_ingredients # percent_ingredient = 100 * volumes[counter] / total_volume # Display "Ingredient", (counter + 1), "-", percent_ingredient, "of total:", volumes[counter], "ml of", names[counter], "at", proofs[counter], "proof." # counter = counter + 1 # End While # percent_alcohol = 100 * total_volume_alcohol / total_volume # Display "Total volume:", total_volume # Display "Total alcohol:", total_volume_alcohol # Display "Total alcohol percent:", percent_alcohol # End Module  def display_recipe(number_of_ingredients, names, volumes, proofs, total_volume, total_volume_alcohol): counter = 0 percent_alcohol = 0.0 percent_ingredient = 0.0 while counter < number_of_ingredients: percent_ingredient = 100 * volumes[counter] / total_volume print("Ingredient", (counter + 1), "-", "{:.2f}".format(percent_ingredient), "of total:", volumes[counter], "ml of", names[counter], "at", proofs[counter], "proof.") counter = counter + 1 percent_alcohol = 100 * total_volume_alcohol / total_volume print("Total volume:", total_volume) print("Total alcohol:", total_volume_alcohol) print("Total alcohol percent:", "{:.2f}".format(percent_alcohol)) # Module drink_recipe() # Declare Strings names[MAX_INGREDIENTS] # Declare Real volumes[MAX_INGREDIENTS] # Declare Real proofs[MAX_INGREDIENTS] # Declare Integer number_of_ingredients # Declare Real total_volume # Declare Real total_volume_alcohol # # number_of_ingredients = get_ingredients(names, volumes, proofs) # total_volume, total_volume_alcohol = calculate_totals(number_of_ingredients, volumes, proofs) # Call display_recipe(number_of_ingredients, names, volumes, proofs, total_volume, total_volume_alcohol) # End Module  def drink_recipe(): names = ["" for x in range(MAX_INGREDIENTS)] volumes = [0.0 for x in range(MAX_INGREDIENTS)] proofs = [0.0 for x in range(MAX_INGREDIENTS)] number_of_ingredients = 0 total_volume = 0.0 total_volume_alcohol = 0.0 number_of_ingredients = get_ingredients(names, volumes, proofs) total_volume, total_volume_alcohol = calculate_totals(number_of_ingredients, volumes, proofs) display_recipe(number_of_ingredients, names, volumes, proofs, total_volume, total_volume_alcohol) drink_recipe() 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions