-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkonvertera.py
More file actions
28 lines (21 loc) · 791 Bytes
/
konvertera.py
File metadata and controls
28 lines (21 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 4 14:41:57 2016
@author: erik.lundin
"""
import urllib.request
import json
conversionUrl = "http://api.fixer.io/latest?base={}"
currencyNamesUrl = "https://openexchangerates.org/api/currencies.json"
currencyNamesJson = urllib.request.urlopen(currencyNamesUrl).read().decode('utf-8')
currencyNames = json.loads(str(currencyNamesJson))
a = input('Konvertera från: ')
a = a.upper()
print(a + ': ' + currencyNames[a])
b = input('till: ')
b = b.upper()
print(b + ': ' + currencyNames[b])
c = float(input('Antal ' + a + ':'))
currencyJson = urllib.request.urlopen(conversionUrl.format(a)).read().decode('utf-8')
currency = json.loads(str(currencyJson))
print('Resultat: ' + str(c) + ' ' + a + ' = ' + str(currency['rates'][b] * c) + ' ' + b)