Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble with While loops
#1
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!
Reply
#2
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: ")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trouble creating loops Den 3 2,302 Oct-23-2019, 05:59 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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