SharedClass Samples / currency_exchange_solution.pyOpen in CoCalc
import sys

#  Ask the user for an amount in dollars to convert
amount = float(raw_input('How much money do you want to convert? '))
if not 100 <= amount <= 1000:
    print 'The amount to exchange should be between 100 and 1000; you entered %f' % amount
    sys.exit()

#  Ask the user for the code for the country they want
destination_currency = raw_input('Which currency do you want to receive? ')

plural_currency = destination_currency + 's'

rate = float(raw_input('What is the exchange rate (1 USD = ? ' + plural_currency + ') '))
if rate <= 0:
    print 'The exchange rate should be a positive value; you entered %f' % rate
    sys.exit()

direction = raw_input('Are you exchanging from US dollars, or to US dollars: ')
if direction == 'from':
    print amount, 'US dollars is', amount*rate, plural_currency
else:
    print amount, plural_currency, 'is', amount/rate, 'US dollars'