Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: CSCI 195
Views: 5930
Image: ubuntu2004
1
import sys
2
3
# Ask the user for an amount in dollars to convert
4
amount = float(raw_input('How much money do you want to convert? '))
5
if not 100 <= amount <= 1000:
6
print 'The amount to exchange should be between 100 and 1000; you entered %f' % amount
7
sys.exit()
8
9
# Ask the user for the code for the country they want
10
destination_currency = raw_input('Which currency do you want to receive? ')
11
12
plural_currency = destination_currency + 's'
13
14
rate = float(raw_input('What is the exchange rate (1 USD = ? ' + plural_currency + ') '))
15
if rate <= 0:
16
print 'The exchange rate should be a positive value; you entered %f' % rate
17
sys.exit()
18
19
direction = raw_input('Are you exchanging from US dollars, or to US dollars: ')
20
if direction == 'from':
21
print amount, 'US dollars is', amount*rate, plural_currency
22
else:
23
print amount, plural_currency, 'is', amount/rate, 'US dollars'
24
25