[Tutor] Random Number Question

Adam Bark adam.jtm30 at gmail.com
Wed Nov 24 23:00:42 CET 2010


On 24/11/10 21:51, Jeff Goodwin wrote:
> Hello,
> I'm trying to find a way to use the random.randint function to 
> generate a random number, but everytime I run the program it locks up 
> IDLE. Here is what I have so far:
> import random
> def main():
>      x = input("Enter a number: ")
>      y = input("Enter a different number: ")
>      z = random.randint(x,y)
> print "The random number between ", x, " and ", y, " is ", z
> main()
> Can you tell me where I'm going wrong here? When I run the program it 
> allows me to enter the numbers for x and y, then freezes.
>
> Thanks!
> Jeff
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>    
Your print statement isn't indented. It should print "the random number 
between" and then throw an exception I think. You should either move the 
print statement into the function or have main return x, y, z and print 
the return values of it.

HTH.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101124/4a2eb5af/attachment-0001.html>


More information about the Tutor mailing list