-
Notifications
You must be signed in to change notification settings - Fork 0
/
E1.1_calculator-v3.py
62 lines (56 loc) · 1.7 KB
/
E1.1_calculator-v3.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
def getCalcOperation():
calcOperations = ["+", "-", "*", "/", "%", "**", "!"]
while True:
calcOp = input("Wählen + - * / % ** ! : ")
if calcOp not in calcOperations:
print ("Keine gültige Rechenoperation. Nochmal")
continue
else:
break
return calcOp
def getNumber(n,calcOp):
while True:
try:
number = int(input("Ganze Zahl " + str(n) + " : "))
if calcOp == "!" and number < 0:
print ("Faktultät nur mit Zahlen größer gleich 0. Nochmal")
continue
elif calcOp == "/" and number == 0:
print ("Nicht durch 0 teilbar. Nochmal")
continue
except ValueError:
print ("Das war keine ganze Zahl. Nochmal")
continue
else:
break
return number
def calculation(number1,number2,calcOp):
while True:
if calcOp == "!":
erg = 1
for i in range(2,number1+1):
erg *= i
print ("Ergebis : " + str(erg))
break
else:
erg = eval(str(number1) + calcOp + str(number2))
print ("Ergebis : " + str(erg))
break
while True:
print ("""
Calculator start: """)
calcOp = getCalcOperation()
num1 = getNumber(1,calcOp)
if calcOp == "!":
num2 = 0
else:
num2 = getNumber(2,calcOp)
calculation(num1,num2,calcOp)
restartInputList = ["y", "yes", "j", "ja"]
restartCalculation = input("""
Nochmal?
Ja [ y ]
Nein [any key]
""")
if restartCalculation.lower() not in restartInputList:
break