【问题标题】:Python currency converter using functions with two functionsPython货币转换器使用具有两个函数的函数
【发布时间】:2016-03-23 22:30:10
【问题描述】:

def main():

Print_menu()
currency_converter()

1) Print_menu 函数应该是无效的,没有参数

定义打印菜单():

print('Please choose from the menu.')       
print('============================')       
print('1: Convert between USD and EUR')     
print('2: Convert between USD and Canada')  
print('3: Convert between USD and UK (GBP)')
print('4: Convert between USD and China')   
print('5: Quit')                            
print('============================')       
menu = int(input('Enter your Choice: '))

2) 这个 currency_converter 函数需要两个参数,汇率和

货币单位名称。这可以是无效的,需要一个汇率和单位

计算并打印结果。我对编写代码非常陌生,不知道如何调用这些函数来创建一个工作程序。提前感谢您的任何意见

def currency_converter():

while menu >=1 and menu <=4:
    if menu == 1:
         menu = int(input('Enter the amount in dollar: '))
         men1 = menu 
         men1 = menu * 91/100 
         print('\t','$', menu,'is', format(men1,'.2f'),'euro')
    elif menu == 2:
        menu = int(input('Enter the amount in dollar: '))
        men1 = menu 
        men1 = menu * 137/100 
        print('\t','$', menu, 'is', format(men1,'.2f'), 'cad')
    elif menu == 3:
        menu = int(input('Enter the amount in dollar: '))
        men1 = menu 
        men1 = menu * 72/100 
        print('\t','$', menu, 'is', format(men1,'.2f'), 'pound')
    elif menu == 4:
        menu = int(input('Enter the amount in dollar: '))
        men1 = menu 
        men1 = menu * 653/100 
        print('\t','$', menu, 'is', men1, 'yuan')

if menu == 5:
    print('Thank you for using my program.')

else:
    print(menu, 'is an invalid choice.')

3) 选择货币后,我需要一个 while 循环来询问是否要转换为-

另一个单位。我目前仍在编写这部分,并且对我能做到这一点充满信心。

main()

【问题讨论】:

  • 欢迎来到 Stack Overflow!请务必以可读的方式格式化您的问题 - 特别是对于这很重要的 python!

标签: function converter currency


【解决方案1】:

我会在 Print_menu 中添加一个 return 语句以返回菜单值并将 def currency_converter(): 更改为 def currency_converter(menu): 然后在主函数中调用其中一个。

def main():
    currency_converter(Print_menu())

if __name__==__main__:main()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多