(Financials: currency exchange) Write a program that prompts the user to enter the currency exchange rate between U.S. dollars and Chinese Renminbi (RMB). Prompt the user to enter 0 to convert from U.S. dollars to Chinese RMB and 1 for vice versa. Prompt the user to enter the amount in U.S. dollars or Chinese RMB to convert it to Chinese RMB or U.S. dollars, respectively. Here are some sample runs:
Enter the exchange rate from dollars to RMB: 6.81
Enter 0 to convert dollars to RMB and 1 vice versa: 0
Enter the dollar amount: 100
$100.0 is 681.0 yuan
Enter the exchange rate from dollars to RMB: 6.81
Enter 0 to convert dollars to RMB and 1 vice versa: 1
Enter the RMB amount: 10000
10000.0 yuan is $1468.43
Enter the exchange rate from dollars to RMB: 6.81
Enter 0 to convert dollars to RMB and 1 vice versa: 5
Incorrect input
print("Enter 0 to convert dollars to RMB and 1 vice versa: ")
option = int(input())
#Prompt the user to enter the amount in USD or RMB
#to convert it to RMB or USD respectively
if(option==0):
print("Enter the dollar amount: ")
amount = float(input())
print("$ {} is {} yuan".format(amount,(amount * rate)))
elif(option==1):
print("Enter the RMB amount: ")
amount =float(input())
rmb=((amount * 100) / rate) / 100.0
print("{} yuan is $ {:.2f}".format(amount,rmb))
elif(option>1):
print("Incorrect input")
Output:
Enter the exchange rate from dollars to RMB:
6.81
Enter 0 to convert dollars to RMB and 1 vice versa:
1
Enter the RMB amount:
10000
10000.0 yuan is $ 1468.43