|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 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
|
|||
|
|||
|
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()
|
|
#3
|
|||
|
|||
|
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
|
|
#4
|
|||
|
|||
|
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! |
|
#5
|
|||
|
|||
|
Quote:
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 |
|
#6
|
|||
|
|||
|
Ivanhope,
Can you explain to me the "n" and what it is/does in this program? Thanks, Munk |
|
#7
|
||||
|
||||
|
Quote:
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. |
|
#8
|
|||
|
|||
|
Thank you!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Need some help if you please |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|