dimanche 3 avril 2022

How to use a while loop that generates 5 random numbers and puts them into a list?

Need help getting random generated numbers to be put into a list after executed 5 times, preferred through a while loop. My code is only printing one number when i need 5. This is what i have so far, plus im fairly new to python so need some tips.

import random

die1 = random.randint(1,6)

result = [ ]

rolls = 0

while rolls < 5:
   ran_die = random.randint(1,6)
   result = ran_die
   rolls = rolls + 1

print(result)

#I want the end results to appear list this. Thank you for help 

[1, 2, 3, 4, 5]



Aucun commentaire:

Enregistrer un commentaire