Nov-22-2017, 05:00 PM
Hello again. First off let me thank you for all your help.
Now, I went back into my code and took a function out and moved some things around. I have it running again with correct validating errors. Only now, it seems that my calculation has gotten mixed up in the process and I am not returning the value(or only the first). Any suggestions would be awesome.
Now, I went back into my code and took a function out and moved some things around. I have it running again with correct validating errors. Only now, it seems that my calculation has gotten mixed up in the process and I am not returning the value(or only the first). Any suggestions would be awesome.
# Constant Integer HOURS = 7 HOURS = 7 def valid_float_number(value): try: float(value) return value except ValueError: print("Please try again.") return False # Function Real real_number(String prompt) # Declare String value # # Display prompt # Input value # While not value is a real number # Input value # End While # Return value # End Function def real_number(prompt): value = "" value = input(prompt) while not valid_float_number(value): value = input(prompt) return value if float(value) < 0 or value == "": print(value, "is less than 0!") value = input(prompt) return value else: return True # Function Real get_pints_for_hours() # # Display prompt # Input Real prompt # # Return user_input # End Function def get_pints_for_hour(): user_input = float(real_number("Enter pints collected: ")) return user_input def get_pints_for_drive(): pints_collected = [0.0 for x in range(HOURS)] counter = 0 while counter < HOURS: pints_collected[counter] = get_pints_for_hour() counter += 1 return pints_collected def calculate_average_pints(pints_collected_during_drive): total_pints = 0 counter = 0 while counter < HOURS: total_pints += pints_collected_during_drive[counter] counter += 1 return float(total_pints / HOURS) # Function display_results(average_pints, mimimum, maximum): # print("The average number of pints donated is ", "{:.2f}".format(average_pints)) # print("The highest pints donated is ", maximum) # print("The lowest pints donated is ", minimum) # End Function def display_results(average_pints, minimum, maximum): print("The average number of pints donated is ", "{:.2f}".format(average_pints)) print("The highest pints donated is ", maximum) print("The lowest pints donated is ", minimum) # Function is_yes_or_no(Real value) # # Return value == "yes" or value == "no" def is_yes_or_no(value): return value == "yes" or value == "Yes" or value == "no" or value == "No" # Function Boolean end_yes_or_no(String prompt) # Declare String value # # Display prompt # Input value # While not is_yes_or_no # Display prompt # Input value # If value == "yes" or value == "YES" # Return True # Else # Return False # End If # End While # End Function def end_yes_or_no(prompt): value = "" value = input(prompt) while not is_yes_or_no(value): value = input(prompt) if value == "yes": return True else: return False # Function prompt_done() # Display prompt # Input prompt # # Return end_yes_or_no(prompt) # End Function def prompt_done(): prompt = "Do you want to end program? (Enter no or yes): " return end_yes_or_no(prompt) def main(): done = False while not done: pints_collected_during_drive = get_pints_for_drive() average_pints = calculate_average_pints(pints_collected_during_drive) minimum_pints = min(pints_collected_during_drive) maximum_pints = max(pints_collected_during_drive) display_results(average_pints, minimum_pints, maximum_pints) done = prompt_done() main()