[Tutor] question
David Holland
davholla2002 at yahoo.co.uk
Wed Apr 12 05:11:59 EDT 2023
This looks like homework but I am practising python myself so I will suggest what I wrote
import random
def print_ran(x):
listnumused = []#list of numbers we have generated
while len(x)> 0:
a = random.choice(x)
listnumused.append(a)
if listnumused.count(a)>3:#once we have used a number 4 times remove it from the list we are going to use
x.remove(a)
print (listnumused)#print the random numbers
if __name__ == '__main__':
x=[1,2,3,4,5]
print_ran(x)
On Wednesday, 12 April 2023 at 08:45:13 BST, Prayash Bhuyan <bhuyanprayash18 at gmail.com> wrote:
I know how to generate random numbers using random function but I want to
know how do i generate random numbers say between (1,5) where each random
number can only be repeated only 4 times........please help
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list