-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathif.py
More file actions
executable file
·83 lines (58 loc) · 1.24 KB
/
if.py
File metadata and controls
executable file
·83 lines (58 loc) · 1.24 KB
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
#!/usr/bin/env python3
# Die if-Bedingung:
boolean3 = True
if boolean3 == True:
print(True)
# Wenn nur geprüft werden soll, ob ein Ausdruck
# <True> ist, kann das '== True' weggelassen werden,
# da der Compiler überprüft, ob der Ausdruck True
# ist.
if boolean3:
print(True)
# if-Bedingung mit else-Zweig:
summertime = True
if summertime:
print("Yeah, it's summer!")
else:
print("Ohh, it's winter!")
# if-Bedingung zum Vergleichen von int-Werten:
a = 5
b = 10
if a > b:
print(a)
else:
print(b)
# Wichtig: Auf die Einrückung achten!
# if-Bedingung mit elif- und else-Zweig:
a = 6
b = 7
if a > b:
print("A")
elif a == b:
print(" ")
elif a < b:
print("B")
else:
print("You broke the math.")
# Verschachtelte if-Bedingungen:
a = 3
b = 4
c = 5
if a < b:
if b < c:
print("C ist der Größte!")
else:
if b > c:
print("B ist der Größte!")
else:
print("B und C sind die Größten!")
else:
if a > b:
if a > c:
print("A ist der Größte!")
else:
if a < c:
print("C ist der Größte!")
else:
print("A und C sind die Größten!")
# Wichtig: Einrückung beibehalten!