-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (65 loc) · 2.66 KB
/
main.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from Currency import Currency
from GUI import GUI
def main():
# file_input("Pepe.txt")
gui = input("Do you want to use the G)UI or C)onsole?: ")
if gui == 'C':
mode = input("Do you wish to import custom currencies via a file? (y or n): ")
valid = False
while not valid:
if mode == "y":
valid = True
dic, new_name = file_input()
o = input("What is your starting currency?: ")
name = input("What do you want to convert to?: ")
amount = float(input("How much do you want to convert?: "))
money = Currency(o, name, amount)
money.add_entry(new_name, dic)
converted = money.convert()
# money.show_rates()
print("Converted {:,.2f} {} to {:,.2f} {}".format(amount, o, converted, name))
elif mode == "n":
valid = True
original = input("What is your starting currency?: ")
amount = float(input("How much do you want to convert?: "))
name = input("What do you want to convert to?: ")
money = Currency(original, name, amount)
converted = money.convert()
# money.show_rates()
print("Converted {:,.2f} {} to {:,.2f} {}".format(amount, original, converted, name))
else:
print("Invalid choice, try again...")
valid = False
else:
GUI().run()
def file_input():
valid = False
while not valid:
filename = input("What is the name of the file?: ")
try:
file = open(filename)
valid = True
except OSError:
print("Error opening file, check file name...")
valid = False
else:
new_dictionary = {}
"""for line in file:
print(line)
l = line.split(' ')
print("l = {}".format(l))
new_dictionary[l[0]] = l[1]"""
with file as fp:
lines = fp.read().splitlines()
# print(lines)
for entry in lines:
split = entry.split(' ') # this makes a list object
new_dictionary[split[0]] = int(split[1])
# print(new_dictionary)
file.close()
name = input("What is the name of this currency?: ")
return new_dictionary, name
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
main()
# See PyCharm help at https://www.jetbrains.com/help/pycharm/