File tree 5 files changed +51
-19
lines changed 5 files changed +51
-19
lines changed Original file line number Diff line number Diff line change 1
1
# if ... elif ... else
2
2
amount_hansueli = 1000
3
3
4
+
4
5
def compare_amount (amount ):
5
6
if amount < amount_hansueli :
6
7
print ("Du bisch ja no ermer als de Hansueli" )
@@ -9,9 +10,11 @@ def compare_amount(amount):
9
10
else :
10
11
print ("Du bisch richer als de Hansueli" )
11
12
13
+
12
14
# switch case
13
15
compare_amount (10000000 )
14
16
17
+
15
18
def switch_color (color ):
16
19
match color :
17
20
case 'red' :
@@ -21,4 +24,4 @@ def switch_color(color):
21
24
case 'green' :
22
25
return "wrong color"
23
26
case 'magenta' :
24
- return "right color"
27
+ return "right color"
Original file line number Diff line number Diff line change 1
1
# Creating and calling Function
2
2
3
3
def my_function ():
4
- print ("Hello from "
5
- "a function" )
4
+ print ("Hello from "
5
+ "a function" )
6
+
6
7
7
8
my_function ()
8
9
10
+
9
11
# Arguments
10
12
def my_function_with_arguments (first_name , last_name ):
11
- print (first_name + " " + last_name )
13
+ print (first_name + " " + last_name )
14
+
12
15
13
16
my_function_with_arguments ("Emil" , "Refsnes" )
14
17
18
+
15
19
# Arbitrary Arguments, *args
16
20
def my_function (* kids ):
17
- print ("The youngest child is " + kids [2 ])
21
+ print ("The youngest child is " + kids [2 ])
22
+
18
23
19
24
my_function ("Emil" , "Tobias" , "Linus" )
20
25
26
+
21
27
# Return Values
22
28
23
29
def my_function (x ):
24
- return 5 * x
30
+ return 5 * x
31
+
25
32
26
- print (my_function (3 ))
33
+ print (my_function (3 ))
Original file line number Diff line number Diff line change 20
20
# The continue Statement
21
21
fruits = ["apple" , "banana" , "cherry" ]
22
22
for x in fruits :
23
- if x == "banana" :
24
- continue
25
- print (x )
23
+ if x == "banana" :
24
+ continue
25
+ print (x )
26
26
27
27
# Else in For Loop
28
28
for x in range (6 ):
29
- print (x )
29
+ print (x )
30
30
else :
31
- print ("Finally finished!" )
31
+ print ("Finally finished!" )
32
32
33
33
# THE range() FUNCTION
34
34
for x in range (6 ):
35
- print (x )
35
+ print (x )
36
36
37
37
# Using the start parameter:
38
38
for x in range (2 , 6 ):
39
- print (x )
39
+ print (x )
40
40
41
41
# Increment the sequence with 3 (default is 1):
42
42
for x in range (2 , 30 , 3 ):
43
- print (x )
44
-
43
+ print (x )
Original file line number Diff line number Diff line change 1
- #Legal variable names:
1
+ # Legal variable names:
2
2
myvar = "John"
3
3
my_var = "John"
4
4
_my_var = "John"
5
5
myVar = "John"
6
6
MYVAR = "John"
7
7
myvar2 = "John"
8
8
9
- #Illegal variable names:
9
+ # Illegal variable names:
10
10
# 2myvar = "John"
11
11
# my-var = "John"
12
12
# my var = "John"
13
13
14
- #Example
14
+ # Example
15
15
name = "deo40"
16
16
price = 12.50
17
17
availability = True
Original file line number Diff line number Diff line change
1
+ max_points = 30
2
+
3
+
4
+ def show_possible_grades ():
5
+ print ("possible grades" )
6
+ for x in range (1 , 7 ):
7
+ print ("\t " , x )
8
+
9
+
10
+ def calculate_grade (points ):
11
+ if points > max_points :
12
+ print ("the points can't be above the max_points of " , max_points )
13
+ return
14
+ your_grade = points / max_points * 5 + 1
15
+ print ("\n your grade is: " , your_grade )
16
+ if your_grade >= 4 :
17
+ print ("well done" )
18
+ else :
19
+ print ("please learn more" )
20
+
21
+
22
+ show_possible_grades ()
23
+ calculate_grade (30 )
You can’t perform that action at this time.
0 commit comments