Python Forum
Trouble with While loops - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Trouble with While loops (/thread-21881.html)



Trouble with While loops - jj432 - Oct-18-2019

Hello, I am trying to get the total, max, min, and average of data entries. Trying to use a while loop but not sure how to get total of entires. This is what I have so far.

print("Welcome! This program will calculate statistics for your integer data.")
number = int(input("Please type a number: "))
next = input("Additional number? (y/n): ")
while next == 'y':
    number = int(input("Next number"))
    next = input("Additional number? (y/n): ")
if next == 'n':
    print("Number analysis: ")
Any help would be greatly appreciated!


RE: Trouble with While loops - Aurthor_King_of_the_Brittons - Oct-19-2019

Create an empty list before the loop to drop the user's input into it during each iteration. Check out this link showing the methods you could use to get what you require.

Methods for lists

Also, if you use the blue and yellow Python code icon above your message, your code will be easier to read (see below):

print("Welcome! This program will calculate statistics for your integer data.")
number = int(input("Please type a number: "))
next = input("Additional number? (y/n): ")
while next == 'y':
    number = int(input("Next number"))
    next = input("Additional number? (y/n): ")
    if next == 'n':
        print("Number analysis: ")