Nov-23-2017, 04:29 PM
Hello again, ok so I rewrote all my code in hopes that I could make it more readable to everyone. I am still battling my validation problem and now min and max won't work. Also, when the user puts in a negative number, instead of looping and inputting the new value, it loops and adds the negative number in its place.
Here is my updated code (I've taken out min and max for the time being):
Here is my updated code (I've taken out min and max for the time being):
PINTS_DATA = 6 def is_actual_float(pints): try: is_actual = float(pints) if is_actual < 0: return False is_actual = True except ValueError: is_actual = False return is_actual def get_pints_for_drive(): pints = 0.0 pints_collected = 0.0 PINTS_DATA = [] counter = 0 while counter <= 6: pints = float(input("Enter pints collected: ")) is_actual = is_actual_float(pints) counter += 1 pints_collected += pints PINTS_DATA.append(pints) while not is_actual: print("Please try again.") pints = float(input("Enter pints collected: ")) is_actual = is_actual_float(pints) input_float = pints print(pints_collected) return pints_collected def calculate_average_pints(pints_collected): average_pints = pints_collected / 7 return average_pints def is_yes_or_no(value): return value == "yes" or value == "Yes" or value == "no" or value == "No" def prompt_done(): prompt = "Do you want to end program? (Enter no or yes): " return end_yes_or_no(prompt) 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 def display_information(average): print("The average of pints collected is: ", average) # print("The minimum number of pints collected: ", minimum_pints) # print("The maximum number of pints collected: ", maximum_pints) def main(): done = False while not done: pints_collected = get_pints_for_drive() average_pints = calculate_average_pints(pints_collected) display_information(average_pints) done = prompt_done() main()