Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a python modular program hat uses at least two arrays, and has at least one loop that accesses the data in the arrays. I

Write a python modular program hat uses at least two arrays, and has at least one loop that accesses the data in the arrays.

I want a very basic one, that just has two arrays. Something similar to

Array 1 = [1,2,3,4,5,6,7,8]

array 2= [j,e,n,n,i,f,e,r]

How could I connect these 2 or similar arrays, following the requirements below? I am looking for a super basic example, much more simple than the one shown below.

I'm open to any ideas.

  • Comments including a brief description of the program, Input List and Output List, and brief psuedocode
  • 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.
  • 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).

----------------------------------------------------------------------------------------------------

Example Program:

 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 def get_string(prompt): value = "" value = input(prompt) return value 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) 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) 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 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 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)) 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

Students also viewed these Databases questions