Currency Converter 4.0
""" Author: Li Xin Function: Currency Converter Version: 5.0 Date: 01/02/2020 2.0 New: The input is judged RMB or US dollars, convert the corresponding calculated 3.0 New feature: you can have the program running until the user chooses to exit 4.0 feature: the exchange rate functions to the function package 5.0 add features: (1) the structure of the program (2) a simple function definition lambda """ # DEF convert_currency (IM, ER): # "" " # exchange rate function # " "" # OUT = IM * ER # return OUT def main(): """ The main function "" " # Exchange rate USD_VS_RMB = 6.77 # With units of currency input currency_str_value the INPUT = ( ' Please enter the amount of money with units: ' ) unit = currency_str_value[-3:] if unit == 'CNY': exchange_rate = 1 / USD_VS_RMB elif unit == 'USD': exchange_rate = USD_VS_RMB else: exchange_rate = -1 if exchange_rate != -1: in_money = the eval (currency_str_value [: -. 3 ]) # using lambda-defined function convert_currency2 = lambda X: X * EXCHANGE_RATE # # Call the function # out_money = convert_currency (in_money, EXCHANGE_RATE) # Call the lambda function out_money = convert_currency2 (in_money) Print ( ' the converted amount: ' , out_money) the else : Print ( ' ! Does not support the currency ' ) if __name__ == '__main__': main()
Knock blackboard! ! ! ! ! !
- Define the variable
- input、print、
- List