1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Rep Power

    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!"
    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Rep Power
    From the random module docs:

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

    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:

    while True:
    and then use:

    if answer == 0:
    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).

IMN logo majestic logo threadwatch logo seochat tools logo