Python Forum
User input only takes the last number
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User input only takes the last number
#14
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):
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()
Reply


Messages In This Thread
User input only takes the last number - by Austin11 - Nov-15-2017, 12:09 AM
RE: User input only takes the last number - by Prrz - Nov-21-2017, 03:28 AM
RE: User input only takes the last number - by Prrz - Nov-21-2017, 04:41 AM
RE: User input only takes the last number - by Prrz - Nov-21-2017, 09:20 PM
RE: User input only takes the last number - by Prrz - Nov-22-2017, 07:13 PM
RE: User input only takes the last number - by Austin11 - Nov-23-2017, 04:29 PM
RE: User input only takes the last number - by Prrz - Nov-23-2017, 08:07 PM
RE: User input only takes the last number - by Prrz - Nov-28-2017, 11:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Simulate an answer based on user input [Beginner needs guidance] Bombardini 1 1,330 Nov-12-2022, 03:47 AM
Last Post: deanhystad
  Checking the number of input Chrilo06 3 2,046 Mar-14-2022, 07:31 PM
Last Post: deanhystad
  Print user input into triangle djtjhokie 1 2,426 Nov-07-2020, 07:01 PM
Last Post: buran
  Changing Directory based on user input paulmerton4pope 13 8,172 Aug-14-2020, 11:48 AM
Last Post: GOTO10
  Creating a link that takes the user to a random page card51shor 9 6,223 Jul-06-2020, 05:38 AM
Last Post: card51shor
  how to add the user input from file into list wilson20 8 4,385 May-03-2020, 10:52 PM
Last Post: Larz60+
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,862 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  Print the longest str from user input edwdas 5 4,217 Nov-04-2019, 02:02 PM
Last Post: perfringo
  how to add user input to a dictionary to a graph KINGLEBRON 3 3,086 Jul-31-2019, 09:09 PM
Last Post: SheeppOSU
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,542 Mar-23-2019, 06:54 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020