def main(): print("US Dollar to Foreign Currency Converter") selected_currency = input( "Please select a currency to convert to. [1] For Euro €. [2] For Japanese Yen ¥. [3] For Mexican Peso $:" ) while selected_currency != "1" and selected_currency != "2" and selected_currency != "3": print("Error. Invalid Selection.") selected_currency = input( "Please select a currency to convert to. [1] For Euro €. [2] For Japanese Yen ¥. [3] For Mexican Peso $:" ) dollar_valid_entry = False while dollar_valid_entry == False: dollar = input("Please enter the amount of US Dollars to convert:") try: dollar = float(dollar) dollar_valid_entry = True while dollar < 0: print("US Dollar value cannot be negative.") dollar_valid_entry = False break except ValueError: print("Invalid entry.") if selected_currency == "1": euro = currency.to_euro(dollar) print("$" + format(dollar, ".2f"), "is converted to", format(euro, ".2f") + "€") elif selected_currency == "2": yen = currency.to_euro(dollar) print("$" + format(dollar, ".2f"), "is converted to JP¥" + format(yen, ".2f")) elif selected_currency == "3": peso = currency.to_euro(dollar) print("$" + format(dollar, ".2f"), "is converted to MEX$" + format(peso, ".2f"))
def main(): while True: currency_type = int( input("Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: ")) if currency_type < 1 or currency_type > 3: print("Error: Invalid Choice") else: break while True: dollar = float(input("Enter US Dollar amount: ")) if dollar < 0: print("Error: US Dollar cannot be negative.") else: break if currency_type == 1: converted_currency = currency.to_euro(dollar) print(f"It is converted to , {converted_currency} Euro") elif currency_type == 2: converted_currency = currency.to_yen(dollar) print(f"It is converted to , {converted_currency} Yen") else: converted_currency = currency.to_peso(dollar) print(f"It is converted to , {converted_currency} Peso")
def main(): """ This program converts USD to one of three foreign currencies """ print('Converting US Dollar to a foreign currency.') currency_to_convert = int( input('Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: ')) while currency_to_convert not in [1, 2, 3]: print('Error: Invalid choice') currency_to_convert = int( input( 'Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: ')) us_dollar_amount = int(input('Enter US Dollar: ')) while us_dollar_amount < 0: print('Error: US Dollar cannot be negative.') us_dollar_amount = int(input('Enter US Dollar: ')) if currency_to_convert == 1: converted_amount = currency.to_euro(us_dollar_amount) print('It is converted to', converted_amount, 'Euro') elif currency_to_convert == 2: converted_amount = currency.to_yen(us_dollar_amount) print('It is converted to', converted_amount, 'Yen') else: converted_amount = currency.to_peso(us_dollar_amount) print('It is converted to', converted_amount, 'Peso')
def currency_calculator(foreign_currency, dollar_amount): """Imports functions from currency module to determine the amount of foreign currency""" if foreign_currency == 1: from currency import to_euro conversion = to_euro(dollar_amount) print("It is converted to ", conversion, 'Euros') elif foreign_currency == 2: from currency import to_yen conversion = to_yen(dollar_amount) print("It is converted to ", conversion, 'Yen') else: from currency import to_peso conversion = to_peso(dollar_amount) print("It is converted to ", conversion, 'Pesos')
def main(): print("Converting US Dollar to a foreign currency.") curr, dollar = 0, -1 while (curr != 1 and curr != 2 and curr != 3): curr = int( input( "Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: ")) if (curr != 1 and curr != 2 and curr != 3): print("Error: Invalid Choice") while (dollar < 0): dollar = int(input("Enter US Dollar: ")) if (dollar < 0): print("Error: US Dollar cannot be negative.") if (curr == 1): print("It is converted to ", currency.to_euro(dollar), " Euro") if (curr == 2): print("It is converted to ", currency.to_yen(dollar), " Yen") if (curr == 3): print("It is converted to ", currency.to_peso(dollar), " peso")
def main(): try: print("Converting US Dollar to a foreign currency. ") foreignCurrency = int(input("Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: ")) while foreignCurrency != 1 and foreignCurrency != 2 and foreignCurrency != 3: print("Error: Invalid Choice ") foreignCurrency = int(input("Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: ")) dollarAmount = int(input("Enter US Dollar: ")) while dollarAmount < 0: print("Error: US Dollar cannot be negative. ") dollarAmount = int(input("Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: ")) if foreignCurrency == 1: conversion = currency.to_euro(dollarAmount) print("It is converted to", conversion, "Euros") elif foreignCurrency == 2: conversion = currency.to_yen(dollarAmount) print("It is converted to", conversion, "Yen") elif foreignCurrency == 3: conversion = currency.to_peso(dollarAmount) print("It is converted to", conversion, "Pesos") except ValueError: print("Error: Invalid Choice. Please restart program.")