[Tutor] Random number selection

Dave Angel d at davea.name
Tue Jan 3 03:36:05 CET 2012

On 01/02/2012 08:52 PM, shane wrote:
> I was wondering is there a way to have a variable generate a random 
> integer each time the variable is called.
> Ive tried random.randint(a,  b) and the range one to.
> It selects a random number and assigns it to the variable
> this part of the program would be math equations
> with random number selections
> x=ran  y=ran z=x*y
> x * y = z
>  s=input=('x*y= ')
>    if s != z
> There are many things I need to solve its my first program.
> But I just need help on assigning a random number and looping through 
> to get diff values for x and y

There's so much wrong with that message I don't know how to respond.  
There is either a grammatical or syntax error on every line.

Variables with integer values are not 'called."  They also don't change 
values unless you change it.  So if you've got a loop, and you want them 
to have different values each time, then give them different values each 
time, by calling a function that does return a different value.

for ......
      x = random.randint(a,b)
      y = random.randint(a,b)
      ...  do something with the values



More information about the Tutor mailing list