-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
122 lines (83 loc) · 3.15 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import platform
# screen cleaning function
def clear_screen():
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear')
# logic functions
def toNumber():
try:
endMoney = float(input("How much money you want to have at the end? "))
try:
startMoney = float(input("How much money you have on start? "))
try:
percent = float(input("What is the interest percent? "))
# convertion of variables
currentMoney = startMoney
interesPercent = percent / 100 + 1
years = 0
#algorithm
while( currentMoney < endMoney):
currentMoney = currentMoney * interesPercent
years = years + 1
#rounding numbers
roundMoney = round(currentMoney, 2)
print(f"You will exceed {endMoney} in {years} year/years, at the end you will have {roundMoney}. \n")
except ValueError:
print("Wrong data typed in, try again! \n")
toNumber()
except ValueError:
print("Wrong data typed in, try again! \n")
toNumber()
except ValueError:
print("Wrong data typed in, try again! \n")
toNumber()
def fromNumber():
try:
startMoney = float(input("How much money you have on start? "))
try:
years = int(input("How many years will the process last (only full years, no 1.5)? "))
try:
percent = float(input("What is the interest percent? "))
pastYears = 0
currentMoney = startMoney
interesPercent = percent / 100 + 1
#algorithm
for pastYears in range(years):
currentMoney = currentMoney * interesPercent
pastYears = pastYears + 1
#rounding numbers
roundMoney = round(currentMoney, 2)
print(f"In {years} year/years and you will have {roundMoney}. \n")
except ValueError:
print("Wrong data typed in, try again! \n")
fromNumber()
except ValueError:
print("Wrong data typed in, try again! \n")
fromNumber()
except ValueError:
print("Wrong data typed in, try again! \n")
fromNumber()
def menu():
print('Compound interest calculator in python\n')
print('1 - count years needed to gain given amount \n')
print('2 - count how much you will earn after given time \n')
try:
choice = int(input("Choose which type of calculations you would like to do: "))
if choice == 1:
clear_screen()
toNumber()
elif choice == 2:
clear_screen()
fromNumber()
else:
print("Wrong data typed in, try again! \n")
menu()
except ValueError:
clear_screen()
print("Wrong data typed in or wrong number chosen, try again! \n")
menu()
#start
menu()