Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old March 28th, 2004, 03:25 PM
Nick125 Nick125 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Albuquerque, New Mexico
Posts: 137 Nick125 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 1 m 38 sec
Reputation Power: 5
Send a message via AIM to Nick125
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

Reply With Quote
  #2  
Old March 28th, 2004, 06:43 PM
Boceifus's Avatar
Boceifus Boceifus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 93 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 2 h 12 m
Reputation Power: 5
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?!?!?

Reply With Quote
  #3  
Old March 29th, 2004, 12:15 AM
Nick125 Nick125 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Albuquerque, New Mexico
Posts: 137 Nick125 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 1 m 38 sec
Reputation Power: 5
Send a message via AIM to Nick125
Quote:
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

I tried this and what I got is that the menu that shows up is repeated when a option is entered.
Thanks,
Nick

Reply With Quote
  #4  
Old March 29th, 2004, 02:44 AM
Boceifus's Avatar
Boceifus Boceifus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 93 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 2 h 12 m
Reputation Power: 5
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Need to restart program after last command


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway