-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAufgabe16.py
161 lines (128 loc) · 2.11 KB
/
Aufgabe16.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Aufgabe 1 (nur zum Ansehen)
# compute 3!
res = 1
for i in range(1, 4):
res *= i
print(res)
# compute 5!
res = 1
for i in range(1, 6):
res *= i
print(res)
# Aufgabe 2 (nur zum Ansehen)
def factorial(n):
res = 1
for i in range(1, n + 1):
res *= i
return res
# Aufgabe 3 (nur zum Ansehen)
def factorial(n):
res = 1
for i in range(1, n + 1):
res *= i
return res
print(factorial(3))
print(factorial(5))
# Aufgabe 4 (nur zum Ansehen)
def max(a, b):
if a > b:
return a
else:
return b
print(max(3, 5))
print(max(5, 3))
print(max(int(input()), int(input())))
# Aufgabe 5 (korrigiert)
def max3(a, b, c):
return max(max(a, b), c)
print(max3(3, 6, 5))
# Aufgabe 6 (nur zum Ansehen)
def f():
print(a)
a = 1
f()
# Aufgabe 7 (nur zum Ansehen)
def f():
a = 1
f()
print(a)
# Aufgabe 8
def f():
a = 1
print(a)
a = 0
print(a)
f()
print(a)
#Aufgabe 9
def factorial(n):
res = 1
for i in range(1, n + 1):
res *= i
return res
for i in range(1, 6):
print(factorial(i), ' = ', i, '!', sep='')
#Aufgabe 10
def f():
print(a)
if False:
a = 0
a = 1
f()
#Aufgabe 11
def f():
global a
a = 1
print(a)
a = 0
print(a)
f()
print(a)
#Aufgabe 12
def factorial(n):
global f
res = 1
for i in range(2, n + 1):
res *= i
f = res
n = int(input())
factorial(n)
print(f)
#Aufgabe 13
# the chunk of code that can be copied from program to program
def factorial(n):
res = 1
for i in range(2, n + 1):
res *= i
return res
# end of the chunk
n = int(input())
f = factorial(n)
print(f)
#Aufgabe 14
a = input()
b = input()
def f(a,b):
return [a + "th", b + "th"]
n, m = f(a, b)
print(n)
print(m)
#Aufgabe 15
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
print(factorial(5))
#Aufgabe 16 (Gelöst)
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
def double_factorial(n):
if n <= 0:
return 1
else:
return n * double_factorial(n - 2)
print(double_factorial(5))