Returning to the main menu

This is the place for queries that don't fit in any of the other categories.

Returning to the main menu

Postby manderson091 » Wed Oct 02, 2013 8:23 pm

Code: Select all
print ("Welcome to your USD Currency Converter!")
g = input("How much money (USD) are you trying to convert? ")
## input is g. g= ammount to be converted in USD#

print ("Please choose from the following options:")
print (" '1' Convert from US Dollars to Euro")
print (" '2' Convert from US Dollars to Mexican Pasos")
print (" '3' Convert from US Dollars to Japanese Yen")
print (" '4' Convert from US Dollars to Canadian Dollars")
print (" '5' Convert from US Dollars to Chinese Yuan")
print (" '0' Return to the main Menu")

g = input()
choice = int(g)
eu_euros = int(g)*.74 #euro equation#
m_pas = int(g)*13.14 # paso equation#
j_yen = int(g)*97.76 # yen equation#
c_can = int(g)*1.03 # canadian dollar equation (c/d = canadian dollar)#
c_yua = int(g)*6.12 # yuan equation#

if choice == 1: # euro process#
   def us_to_euro(eu_euros):
        return .74*input(eu_euros)
if choice == 2: # paso process#
    def us_to_pasos(m_pas):
        return 13.14*input(m_pas)
if choice == 3: # yen process#
    def us_to_yen(j_yen):
        return 97.76*input(j_yen)
if choice == 4: # c/d process#
    def us_to_canadian(c_can):
        return 1.03*input(eu_euros)
if choice == 5: # yuan process#
    def us_to_yuan(c_yua):
        return 6.12*input(c_yua)
       
if choice == 1: #printing results: euro#
    print ("Euros: ",eu_euros)
if choice == 2: #printing results: paso#
    print ("Pasos: ",m_pas)
if choice == 3: #printing results: yen#
    print ("Yen: ",j_yen)
if choice == 4: #printing results: c/d#
    print ("Canadian Dollars: ",c_can)
if choice == 5: #printing results: yuan#
    print ("Chinese Yuan: ",c_yua)


this is my current code. i'm trying to make it return to the main menu when i press the button "0". and also loop when the task has completed.
thanks!
Last edited by micseydel on Wed Oct 02, 2013 9:09 pm, edited 1 time in total.
Reason: First post lock.
manderson091
 
Posts: 3
Joined: Wed Oct 02, 2013 8:20 pm

Re: Returning to the main menu

Postby stranac » Thu Oct 03, 2013 7:43 am

You are probably going to want to use a while loop.

And a few unrelated things:
Defining functions inside if/else blocks is rarely a good idea,
Using a dictionary maping user selection to an appropriate action could make your code simpler.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1143
Joined: Thu Feb 07, 2013 3:42 pm

Re: Returning to the main menu

Postby dboxall123 » Thu Oct 03, 2013 11:04 am

Wow, I never knew that functions could be defined inside if blocks. That looks weird!
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Returning to the main menu

Postby manderson091 » Thu Oct 03, 2013 8:39 pm

i've been trying to use the while loop, it just isn't working for me, haha.

&& i'm taking a class on this language, that's the way we were taught to do it. i didn't know there were other ways!
manderson091
 
Posts: 3
Joined: Wed Oct 02, 2013 8:20 pm

Re: Returning to the main menu

Postby stranac » Thu Oct 03, 2013 8:59 pm

You should post your attempt at using a while loop to do what you want.
Then we can help fix your problems.

Also, do give us more details than just "it's not working", such as a traceback if there's one, and any differences beetwen the output you're getting and the one you want.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1143
Joined: Thu Feb 07, 2013 3:42 pm

Re: Returning to the main menu

Postby manderson091 » Thu Oct 03, 2013 10:26 pm

update: i got the program working perfectly fine. i was double defining integers and mixing them up. the while code worked just fine when i corrected the error. thanks everyone for the help!
manderson091
 
Posts: 3
Joined: Wed Oct 02, 2013 8:20 pm

Re: Returning to the main menu

Postby micseydel » Fri Oct 04, 2013 10:19 pm

manderson091 wrote:update: i got the program working perfectly fine. i was double defining integers and mixing them up. the while code worked just fine when i corrected the error. thanks everyone for the help!

Could we see your code? I'm curious how it ended up. And based on seeing the first bit of code you posted, it may be in your best interest to find out from us if there are bad habits you're forming that should be corrected.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1354
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests