40 lines
988 B
Python
40 lines
988 B
Python
from math import sqrt
|
|
|
|
|
|
class calculator():
|
|
|
|
def __init__(self):
|
|
self.mem_number_1 = 0
|
|
self.mem_number_2 = 0
|
|
self.mem_res = 0
|
|
|
|
# nimmt a^2 + b^2 und zieht die Wurzel für c
|
|
def pythagoras(self, numA, numB):
|
|
numA = numA**2
|
|
numB = numB**2
|
|
summe = self.addition(numA, numB)
|
|
numC = sqrt(summe)
|
|
self.mem_res = numC
|
|
return numC
|
|
|
|
# addiert 2 Werte
|
|
def addition(self, a, b):
|
|
result = a + b
|
|
self.mem_res = result
|
|
return result
|
|
|
|
# wiederholt fortlaufend
|
|
if __name__ == "__main__":
|
|
while True:
|
|
current_calc = calculator()
|
|
print("Enter values")
|
|
a = int(input("a: "))
|
|
b = int(input("b: "))
|
|
operation = int(input("What to do: [1 : Addition, 2 : Pythagoras]: "))
|
|
|
|
if operation == 1:
|
|
print("Summe: ", current_calc.addition(a, b))
|
|
elif operation == 2:
|
|
print("c: ", current_calc.pythagoras(a, b))
|
|
|
|
|