52 lines
1.1 KiB
Python
52 lines
1.1 KiB
Python
# Author: Jan-Niclas Loosen
|
|
# Matrikelnummer: 1540907
|
|
|
|
# AUFGABE 0
|
|
def pi(run=1000):
|
|
return 4 * pi_quarter(run)
|
|
|
|
|
|
def pi_quarter(run=1000):
|
|
ret = 1
|
|
for i in range(run):
|
|
add = 3 + i*2
|
|
if i%2 == 0:
|
|
ret -= 1 / add
|
|
else:
|
|
ret += 1 / add
|
|
return ret
|
|
|
|
|
|
# example for main routine
|
|
print("pi/4: "+str(pi_quarter()))
|
|
print("pi: "+str(pi())+"\n")
|
|
|
|
|
|
# AUFGABE 02
|
|
def convert_to_f(deg):
|
|
return round(deg * (9/5) + 32, 2)
|
|
|
|
|
|
def convert_to_c(deg):
|
|
return round((deg-32) * (5/9), 2)
|
|
|
|
|
|
def dialog():
|
|
deg = input("Degrees: ")
|
|
mode = input("convert to fahrenheit (0) or convert to celsius (1): ")
|
|
try:
|
|
if mode == "0":
|
|
print(str(convert_to_f(float(deg))) + "\n")
|
|
elif mode == "1":
|
|
print(str(convert_to_c(float(deg))) + "\n")
|
|
else:
|
|
print("invalid mode\n")
|
|
except Exception:
|
|
print("invalid input\n")
|
|
|
|
|
|
# example for main routine
|
|
again = input("convert (1) or exit (other inputs): ")
|
|
while again == "1":
|
|
dialog()
|
|
again = input("convert (1) or exit (other inputs): ") |