-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator_v3.0.py
69 lines (61 loc) · 2.78 KB
/
calculator_v3.0.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class textColor:
RESET = '\033[0m'
BOLD = '\033[01m'
GREEN = '\033[32m'
ORANGE = '\033[33m'
### funkcija račun ###
def operacija(x, znak, y):
if znak == "+":
izracun = float(x) + float(y)
elif znak == "-":
izracun = float(x) - float(y)
elif znak == "*":
izracun = float(x) * float(y)
elif znak == "/":
izracun = float(x) / float(y)
print textColor.GREEN + textColor.BOLD + str(x) + " + " + str(y) + " = " + (str(round(izracun, 3))).rstrip('0').rstrip('.') + textColor.RESET if '.' in (
str(round(izracun, 3))) else (str(round(izracun, 3))) + textColor.RESET
return str(x) + " + " + str(y) + " = " + (
str(round(izracun, 3))).rstrip('0').rstrip('.') if '.' in (str(round(izracun, 3))) else (str(round(izracun, 3)))
### END funkcija račun ###
def kalkulator():
while True:
racun = raw_input("\nZa izhod pritisni " + textColor.GREEN + textColor.BOLD + "X" + textColor.RESET + ", za zgodovino pritisni " + textColor.GREEN + textColor.BOLD + "H" + textColor.RESET + " za nov račun pritisni " + textColor.GREEN + textColor.BOLD + "katerokoli" + textColor.RESET + " drugo tipko! ")
if racun == "x" or racun == "x":
print "Hvala!"
break
elif racun == "H" or racun == "h":
print "Zgodovina dejavnosti:"
for element in history:
print textColor.GREEN + textColor.BOLD + element + textColor.RESET
else:
todo_list = []
while True:
stevilo = raw_input("Vnesite stevilo število: ")
if stevilo.isalpha() or len(
stevilo) == 0 or " " in stevilo or "+" in stevilo or "-" in stevilo or "*" in stevilo or "/" in stevilo:
print "\033[91mTo ni število\033[0m"
else:
todo_list.append(stevilo)
break
while True:
znak = raw_input("Vnesi željeno funkcijo (+, -, * ali /): ")
if not znak in ("+", "-", "*", "/"):
print "\033[91mNepoznana funkcija\033[0m"
else:
todo_list.append(znak)
break
while True:
stevilo = raw_input("Vnesite stevilo število: ")
if stevilo.isalpha() or len(
stevilo) == 0 or " " in stevilo or "+" in stevilo or "-" in stevilo or "*" in stevilo or "/" in stevilo:
print "\033[91mTo ni število\033[0m"
else:
todo_list.append(stevilo)
break
history_list = operacija(todo_list[0], todo_list[1], todo_list[2])
history.append(history_list)
history = []
kalkulator()