0

Hi all, I was wondering if someone could help me with this bit of coding. I have set two veriables d1 and d2 to pick a random int of 1 to 10: which I need for in loop but when I run it the same number appear How do I get a differnt verity of numbers during for in loop in Python 3.1.3 please... Thanks for your time.

# generate random number a certian number of times
import random
# set vers
d1= random.randint(1 ,10)
d2= random.randint(1,10)
# now print different number 10 times
for count in range(1,11):
   print (d1,d2)

#keep getting same numbers when run

Edited by Nick Evan: Removed color and bold tags, Ouch, my eyes...

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by FAITH2011
1

Create your random numbers inside the loop, something like this ...

# generate random number a certain number of times

import random

# now print different number 10 times
for count in range(1,11):
    # create random numbers
    d1= random.randint(1,10)
    d2= random.randint(1,10)
    print (d1,d2)

Edited by vegaseat: like

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.