Python Forum
Finding MINIMUM number in a random list is not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding MINIMUM number in a random list is not working
#6
I refactored your initial code a bit:
import random

# these three lines are obsolete as variables doesn´t need to be "initialized"

# random_numbers = []
# average = 0
# total = 0

# this for loop can be simplified

# for i in range(3):
#     x = int((random.randint(0, 9)))
#     random_numbers.append(x)
#     total = sum(random_numbers)    # why are you calculating the total value each loop ???
#     average = float(total / 3)    # why are you calculating the average each loop ???

amount = 11

random_numbers = [random.randint(0, 9) for x in range(amount)]

print(f"Numbers: {random_numbers}")
print(f"Low: {min(random_numbers)}")
print(f"High: {max(random_numbers)}")
total = sum(random_numbers)
print(f"Total: {total}")
print(f"Average: {total/amount:.2f}")
Reply


Messages In This Thread
RE: Finding MINIMUM number in a random list is not working - by ThomasL - Nov-18-2019, 07:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sample random, unique string pairs from a list without repetitions walterwhite 1 401 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  Error is finding mean of a list PythonBoy 4 843 Sep-11-2023, 02:38 PM
Last Post: PythonBoy
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,012 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Finding combinations of list of items (30 or so) LynnS 1 836 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  List of random numbers astral_travel 17 2,531 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,428 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  Finding the price based on industry and number of transactions chandramouliarun 0 897 Jul-26-2022, 07:36 PM
Last Post: chandramouliarun
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,757 Jul-01-2022, 01:23 PM
Last Post: deanhystad
Question Finding string in list item jesse68 8 1,798 Jun-30-2022, 08:27 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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