Python Forum
numbers in list - max value and average
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numbers in list - max value and average
#1
Program ask user for input (how many fish he caught per day - 10 days) and than it needs to output average per day and output number from list that is higher than average

list = []
above_average = 0
i = 1
while i < 11:
    fish = int(input("Catched fish today: "))
    list.append(fish)
    i+=1
    average = sum(list) / len(list)
    if fish > average:
        above_average += 1
print ("Average per day: " + str(average))
print ("Catch above average " + str(above_average))
This is what i've done and it works but at catch above average i need to print which number from list is higher than average not how many...
Reply
#2
Fisherman Alex needs to enter amount of fish he catched every day for 10 days.

Program needs to return average for every day and number of day he catched more fish than average

list = []
above_average = 0
i = 1
while i < 11:
    fish = int(input("Catched fish today: "))
    list.append(fish)
    i+=1
    average = sum(list) / len(list)
    if fish > average:
        above_average += 1
print ("Average per day: " + str(average))
print ("Catch above average " + str(above_average))


This is what i've done and it works but at catch above average i need to print which number from list is higher than above not how many...
Reply
#3
you need to store the user input in a list. Then, after all numbers are in the list - iterate over list and find [count of] numbers that are higher than average
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,369 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 2,935 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Return the sum of the first n numbers in the list. pav1983 3 3,956 Jun-24-2020, 03:37 AM
Last Post: deanhystad
  Question about Sorting a List with Negative and Positive Numbers Than999 2 12,593 Nov-14-2019, 02:44 AM
Last Post: jefsummers
  list of odd numbers cffiver2 2 5,144 Jul-12-2019, 09:46 AM
Last Post: perfringo
  CODE for Bubble sorting an unsorted list of 5 numbers. SIJAN 1 2,255 Dec-19-2018, 06:22 PM
Last Post: ichabod801
  Python List with Total and Average mcnhscc39 3 3,040 Nov-28-2018, 09:02 AM
Last Post: DeaD_EyE
  Finding the average of numbers in a txt file piday 1 19,113 Feb-27-2018, 04:00 AM
Last Post: Larz60+
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,054 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE
  List with Random Numbers AnjyilLee 5 9,259 Oct-14-2017, 09:22 PM
Last Post: buran

Forum Jump:

User Panel Messages

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