[Tutor] Random Number Question
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@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Random Number Question
Thanks Adam, that was a typo on my part, in the program the print is actually indented. Any other suggestions? Thanks again! Jeff On Wed, Nov 24, 2010 at 5:00 PM, Adam Bark wrote: > 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@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. > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Random Number Question
Ok, I found the problem, I had saved the file as random.py looks like that was a no-no. Its working now that I changed the name. Thanks! Jeff On Wed, Nov 24, 2010 at 5:06 PM, Jeff Goodwin wrote: > Thanks Adam, that was a typo on my part, in the program the print is > actually indented. Any other suggestions? > > Thanks again! > Jeff > > > > On Wed, Nov 24, 2010 at 5:00 PM, Adam Bark wrote: > >> 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@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. >> > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Random Number Question
Thanks Adam and Alan for responding, I'm very much a non-programmer, but my 14 year old son wants to learn, so I have to learn to teach him...slow process lol. Happy Thanksgiving! Jeff On Wed, Nov 24, 2010 at 8:27 PM, Alan Gauld wrote: > > "Jeff Goodwin" wrote > > Ok, I found the problem, I had saved the file as random.py looks like >> that >> was a no-no. Its working now that I changed the name. >> > > Yes that's a bad idea. You probably figured out why, but just in case... > > >>>> import random >>>> >>> > It tries to import itself, which then tries to import itself, > which then. infinite loop time... > > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Print/Loop Question
I'm trying to run the below program and get it to print out feedback as the loop goes. However, if you enter a number too high or too low, it skips the print statement under the if and elif clauses and asks the user to "Guess a number between 1-100" again. Any suggestions on how to get it to print the "too high" and "too low" responses?? Once the number is entered correctly it prints "Just Right" and exits correctly. number = 44 while guess != number : guess = int(raw_input("Guess a number between 1 - 100: ")) *if* guess > number : *print* ("Too high") *elif* guess < number : *print* ("Too low") *else*: *print* ("Just right" ) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor