Skip to content

Commit e1bf5e6

Browse files
committed
reformats old files and adds documents and the exercise_solutions.py
1 parent c4876b0 commit e1bf5e6

File tree

5 files changed

+51
-19
lines changed

5 files changed

+51
-19
lines changed

conditions.py renamed to code/example/conditions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# if ... elif ... else
22
amount_hansueli = 1000
33

4+
45
def compare_amount(amount):
56
if amount < amount_hansueli:
67
print("Du bisch ja no ermer als de Hansueli")
@@ -9,9 +10,11 @@ def compare_amount(amount):
910
else:
1011
print("Du bisch richer als de Hansueli")
1112

13+
1214
# switch case
1315
compare_amount(10000000)
1416

17+
1518
def switch_color(color):
1619
match color:
1720
case 'red':
@@ -21,4 +24,4 @@ def switch_color(color):
2124
case 'green':
2225
return "wrong color"
2326
case 'magenta':
24-
return "right color"
27+
return "right color"
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
# Creating and calling Function
22

33
def my_function():
4-
print("Hello from "
5-
"a function")
4+
print("Hello from "
5+
"a function")
6+
67

78
my_function()
89

10+
911
# Arguments
1012
def my_function_with_arguments(first_name, last_name):
11-
print(first_name + " " + last_name)
13+
print(first_name + " " + last_name)
14+
1215

1316
my_function_with_arguments("Emil", "Refsnes")
1417

18+
1519
# Arbitrary Arguments, *args
1620
def my_function(*kids):
17-
print("The youngest child is " + kids[2])
21+
print("The youngest child is " + kids[2])
22+
1823

1924
my_function("Emil", "Tobias", "Linus")
2025

26+
2127
# Return Values
2228

2329
def my_function(x):
24-
return 5 * x
30+
return 5 * x
31+
2532

26-
print(my_function(3))
33+
print(my_function(3))

loops.py renamed to code/example/loops.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,24 @@
2020
# The continue Statement
2121
fruits = ["apple", "banana", "cherry"]
2222
for x in fruits:
23-
if x == "banana":
24-
continue
25-
print(x)
23+
if x == "banana":
24+
continue
25+
print(x)
2626

2727
# Else in For Loop
2828
for x in range(6):
29-
print(x)
29+
print(x)
3030
else:
31-
print("Finally finished!")
31+
print("Finally finished!")
3232

3333
# THE range() FUNCTION
3434
for x in range(6):
35-
print(x)
35+
print(x)
3636

3737
# Using the start parameter:
3838
for x in range(2, 6):
39-
print(x)
39+
print(x)
4040

4141
# Increment the sequence with 3 (default is 1):
4242
for x in range(2, 30, 3):
43-
print(x)
44-
43+
print(x)

variables.py renamed to code/example/variables.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#Legal variable names:
1+
# Legal variable names:
22
myvar = "John"
33
my_var = "John"
44
_my_var = "John"
55
myVar = "John"
66
MYVAR = "John"
77
myvar2 = "John"
88

9-
#Illegal variable names:
9+
# Illegal variable names:
1010
# 2myvar = "John"
1111
# my-var = "John"
1212
# my var = "John"
1313

14-
#Example
14+
# Example
1515
name = "deo40"
1616
price = 12.50
1717
availability = True

code/exercise/exercise_solutions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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("\nyour 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)

0 commit comments

Comments
 (0)