|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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: print "Your Right!" else: print "Sorry, thats not it." print "Do you want to play again?" print "y or n" y = 1 n = 0 answer = input("> ") if answer == 0: test = 0; print "Okay, maybe some other time then." |
|
#2
|
|||
|
|||
|
From the random module docs:
Quote:
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 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|