Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
June 21st, 2004, 06:46 PM
 Ice Man
Registered User

Join Date: Jun 2004
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
newbie needs help whith his first project

i have a small problem. i have no clue how to create a random number. i tried to look it up but that all goes way over my head. i had a problem getting the program to play more than once but my friend pointed me in the right direction with the test thing, then told me to figure out the number thing i needed to go ask other programers. or go make my own solution, so after much cussin i came looking for help. please help me.
test = 1
while test == 1:
print "Do ya wanna play a game?"
guess = input("Guess a number between 1 and ten.")
if guess == 5:
else:
print "Sorry, thats not it."
print "Do you want to play again?"
print "y or n"
y = 1
n = 0
test = 0;
print "Okay, maybe some other time then."

#2
June 21st, 2004, 06:56 PM
 NetBSD
Contributing User

Join Date: Apr 2004
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
From the random module docs:

Quote:
 randint(a, b) Return a random integer N such that a <= N <= b.

So use :

Code:
```import random
random.randint(min, max) #replace min and max with your values```

Also, in your code you don't need to use the test variable, you can just use:

Code:
`while True:`

and then use:

Code:
```if answer == 0:
break```

Also, from what is looks like, you don't need the y and n variables at all.

and don't forget to use [ code ] [ /code ] tags next time (http://forums.devshed.com/misc.php?do=bbcode#code).

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > newbie needs help whith his first project