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

    Join Date
    Nov 2004
    Posts
    9
    Rep Power
    0

    Need some help if you please


    Okay, first let me say I just started with Python and this is for a college class I'm taking. The progam below works just fine in the interactive window, however if I open the program in windows I input the selection and then the window closes RAPIDLY. I'd like to give the user an option to play again or to exit only I don't know how...can someone give me a hand?

    Much appreciated!
    Munk

    # This program will determain if you are young or old!
    print "welcome to the age program"
    print "---------------------------------------"
    print

    # Print out the menu:
    print "Please select an age group:"
    print "1 16-20"
    print "2 21-25"
    print "3 26-30"
    print "4 31-35"
    print "5 36-40"
    print "6 41-45"
    print "7 46-50"
    print "8 51-60"
    print "9 61-70"
    print "10 >70"


    # Get the user's choice:
    Choice = input ("> ")

    # Return a response after user input:
    if Choice == 1:
    print "You are very Young!"
    if Choice == 2:
    print "You are still Young"
    if Choice == 3:
    print "Still young, but lookout at 30!"
    if Choice == 4:
    print "Middle age...sorry!"
    if Choice == 5:
    print "Pushing 40...now you're in trouble!"
    if Choice == 6:
    print "Over 40, not OLD but getting there"
    if Choice == 7:
    print "Okay now you are well on your way!"
    if Choice == 8:
    print "Life is almost over"
    if Choice == 9:
    print "You are officially OLD!"
    if Choice == 10:
    print "Over 70! You are older than DIRT!"
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    35
    Rep Power
    10
    Code:
    # This program will determain if you are young or old!
    print "welcome to the age program"
    print "---------------------------------------"
    print
    
    restart = "yes"
    
    while restart != "no":
      print "\n\n", """Please select an age group:
      1-)  16-20
      2-)  21-25
      3-)  26-30
      4-)  31-35
      5-)  36-40
      6-)  41-45
      7-)  46-50
      8-)  51-60
      9-)  61-70
      10-)  >70"""
    
      answer = ["\nYou are very Young!", 
    "\nStill young, but lookout at 30!", 
    "\nMiddle age...sorry!", 
    "\nPushing 40...now you're in trouble!", 
    "\nOver 40, not OLD but getting there" , 
    "\nOkay now you are well on your way!", 
    "\nLife is almost over", "\nYou are officially OLD!", 
    "\nOver 70!  You are older than DIRT!"]
    
    
      # Get the user's choice:
      option = int(raw_input ("> "))
      print answer[option - 1]
      
      restart = raw_input("\n\n\tWould you like to play again? >")
      restart = restart.lower()
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    35
    Rep Power
    10
    You could just ask the user in what year did he born or how old is he and the program should calculate itself the age range
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    9
    Rep Power
    0
    I would however I have to stick to the assignment limitations. Okay different questions....is there a statement that I could put in that would keep the window from closing so the user could at least read the answer?

    Thanks for the help ivanhope!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    35
    Rep Power
    10
    Originally Posted by PA_Munk
    I would however I have to stick to the assignment limitations. Okay different questions....is there a statement that I could put in that would keep the window from closing so the user could at least read the answer?

    Thanks for the help ivanhope!
    well in this case the program allways will ask if he wants to continue so it will wait untilo the user do something to close the window

    you can write raw_input() just for wait til the user press enter
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    9
    Rep Power
    0
    Ivanhope,

    Can you explain to me the "n" and what it is/does in this program?

    Thanks,
    Munk
  12. #7
  13. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    Originally Posted by PA_Munk
    Ivanhope,

    Can you explain to me the "n" and what it is/does in this program?
    It is actually "\n" (a backslash followed by a lowercase n), and it stands for 'new line'. In Python (and several other languages, including C, Perl, and Java), the backslash character is used to mark what are called 'escape codes'. They are used to represent non-printable characters in strings. According to this page, Python supports the following character escape codes:
    Code:
     \               Newline Continuation
     \\              Backslash
     \'              Single quote
     \"              Double quote
     \a              Bell
     \b              Backspace
     \e              Escape
     \n              Line feed
     \v              Vertical tab
     \t              Horizontal tab
     \r              Carriage return
     \0              Null
     \0XX            Octal character value
     \xXX            Hex character value
    in the last two cases, the 'XX' stands for two octal or hexadecimal digits; the value is used to insert the corresponding ASCII character. For example, '\x7F' would insert the ASCII DEL (delete) character.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    9
    Rep Power
    0
    Thank you!

IMN logo majestic logo threadwatch logo seochat tools logo