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
  Entry field random pull from list, each return own line Bear1981 6 942 Feb-25-2025, 06:09 AM
Last Post: Pedroski55
  List comprehension not working right Cris9855 3 1,082 Nov-04-2024, 03:46 PM
Last Post: DeaD_EyE
  "Random" module is not working as expected Genericgamemaker 1 1,044 Jul-25-2024, 04:46 PM
Last Post: Gribouillis
  Finding the price based on industry and number of transactions chandramouliarun 1 1,806 Jun-04-2024, 06:57 PM
Last Post: marythodge4
  Sample random, unique string pairs from a list without repetitions walterwhite 1 2,071 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  Error is finding mean of a list PythonBoy 4 1,956 Sep-11-2023, 02:38 PM
Last Post: PythonBoy
  Delete strings from a list to create a new only number list Dvdscot 8 3,551 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 7,741 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Finding combinations of list of items (30 or so) LynnS 1 1,592 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  List of random numbers astral_travel 17 6,063 Dec-02-2022, 10:37 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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