dimanche 1 mars 2015

Loop an answer Python

I have a an answer which I want to loop 10 times. The code looks like this right now:



top = int(input("Please tell us the highest number in the range: "))
bottom = int(input("Tell us the lowest number in the range: "))
print("Batman picks the number",random.randint(bottom,top),"from the range between",bottom,"and",top)


This leaves me with the answer:

Please tell us the highest number in the range: 100

Tell us the lowest number in the range: 10

Batman picks the number 57 from the range between 10 and 100


Now I want to let Batman pick 10 random number from the range. I was thinking in the ways of this:



print("Batman picks the number",random.sample((bottom,top), 10),"from the range between",bottom,"and",top)


The problem is I get an error message saying: ValueError: Sample larger than population

What do I have to populate? Do I need another variable? Thanks in advance. Regards Thomas





Aucun commentaire:

Enregistrer un commentaire