|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Need to restart program after last command
I am trying to make a calculator that after the last operation is done, the program restarts.
This is the ending code: Code:
amount = input("Enter The Amount Saved Per Period: ")
period = input("Enter The Amount of Periods: ")
print "Amount Saved: ", amount * period
print "Thank You For Using OS Calc", version
I have look in the forums and have not found the answer to this. Thanks, Nick ![]() |
|
#2
|
||||
|
||||
|
Wrap your code inside a while True loop...
Allow them to exit the program by inputing 'quit' or 'q' example: Code:
while True:
answer = raw_input('Please choose a function or type "quit" to exit:')
if answer == 'your first function here':
print 'do your first function'
elif answer == 'your second function here':
print 'do your second function'
elif answer == 'quit':
break
Code Block Generated With Py2Html
__________________
It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!? |
|
#3
|
|||
|
|||
|
Quote:
I tried this and what I got is that the menu that shows up is repeated when a option is entered. Thanks, Nick ![]() |
|
#4
|
||||
|
||||
|
Hehe,yes,probably because you weren't inputing a defined answer...In the example,you need to type in "your first function here" or "your second function here" or "quit" to get a response(I didn't know what words you used for your functions,or how many functions you have etc.Perhaps posting more of your code would avoid this in the future).Otherwise it just loops thru until you type in a response it reconizes.Perhaps I should have worded it better and included the "else" statement that I assumed you would use...That was very general example,but maybe one thats a little more specific was called for:
Code:
thankyou = "Thank You For Using OS Calc, Version X \n"
while True:
print 'You can calculate "Total" or "Average" Savings, or "Quit"'
choice = raw_input('What would you like to calculate? ')
if choice == 'Total':
amount = input("\nEnter The Amount Saved Per Period: ")
period = input("Enter The Amount of Periods: ")
print "Amount Saved: ", amount*period
print thankyou
elif choice == 'Average':
amount = input("\nEnter The Total Amount Saved: ")
period = input("Enter The Amount of Periods: ")
print "Average Amount Saved Per Period: ", amount/period
print thankyou
elif choice == 'Quit':
print '\n'+thankyou+'Good Bye!'
break
else:
print '\nInvalid input!\n'
Code Block Generated With Py2Html p.s. Incase you're wondering, whenever I put a '\n' in there,it's just for spacing to make things easier on the eye.It's the equivalent of typing and hitting <enter> to skip a line. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Need to restart program after last command |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|