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

    Join Date
    Apr 2005
    Posts
    14
    Rep Power
    0

    python beginner help


    i am making a program that has u guess a number between one and 20, with 3 chances to get it right; i have this so far:


    y = 0
    x = input('Pick a number between one and twenty. ')

    while x > 7:
    x = input('Smaller. ''Try again. ')
    y = y + 1
    if y == 2:
    print 'Sorry. ''The number was seven. '

    while x < 7:
    x = input('Bigger. ''Try again. ')
    y = y + 1
    if y == 2:
    print 'Sorry. ''The number was seven. '

    if x == 7:
    print 'Correct. '

    it doesnt work right. waht am i doing wrong? pleaz help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    51
    Rep Power
    10

    Hi


    Well I am also new to python....
    But I have had a lot of help that I am understanding the way python work myself>>>

    So hope this help!

    num = 9
    attempts = 3

    for k in range(attempts):
    num = input("make a guess: ")
    print
    if num <1 or num >20:
    print"Your guess is out of range\n"

    elif num == 9:
    print"Your guess is correct\n"
    break

    elif num < 9:
    print"Too low, try again\n"
    print
    elif num > 9:
    print
    print"Too high, try again\n"
    else :
    print "You have ran out of attempts"
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    51
    Rep Power
    10
    Originally Posted by pord_80
    Well I am also new to python....
    But I have had a lot of help that I am understanding the way python work myself>>>

    So hope this help!

    num = 9
    attempts = 3

    for k in range(attempts):
    num = input("make a guess: ")
    print
    if num <1 or num >20:
    print
    print"Your guess is out of range\n"

    elif num == 9:
    print"Your guess is correct\n"
    break

    elif num < 9:
    print
    print"Too low, try again\n"
    elif num > 9:
    print
    print"Too high, try again\n"
    else :
    print "You have ran out of attempts"

    Try to mind indentations if you want to copy this example...
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    615
    Rep Power
    65

    Smile


    I corrected the last code a little bit.
    PHP Code:
    # guess a number

    pick 7
    chances 
    3

    print "Guess a number between 1 and 20"
    print "You have"chances,"chances"

    for k in range(chances):
      
    num input("Make a guess: ")
      if 
    num or num 20:
        print 
    "Your guess is out of range!"
      
    elif num == pick:
        break 
      
    elif num pick:
        print 
    "Too low, try again!"
      
    elif num pick:
        print 
    "Too high, try again!"

    if num == pick:
      print 
    "Your guess is correct!"
    else:
      print 
    "You have run out of chances!" 
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    51
    Rep Power
    10
    Good work, both output basically the same result......
    But I guess you can never know too much.
    That is my philosophy

    Keep it going guys.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    14
    Rep Power
    0

    thx!!!!


    thx alot, guys. it worked.

IMN logo majestic logo threadwatch logo seochat tools logo