Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6b7bd0d

Browse files
authored
Add all exercises of lesson 1.
1 parent 3821063 commit 6b7bd0d

File tree

6 files changed

+189
-0
lines changed

6 files changed

+189
-0
lines changed

‎Lesson-01/pe1_1.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'''
2+
3+
Introduction To Computing Using Python (Werkboek)
4+
5+
Starten met Python (Perkovic - §1.1 t/m §2.3)
6+
7+
Practice Exercise 1.1 (expressions)
8+
Noteer van elke expressie wat de uitkomst en het type is:
9+
10+
'''
11+
12+
print(5) # 5
13+
print(type(5)) # int
14+
15+
print(5.0) # 5.0
16+
print(type(5.01)) # float
17+
18+
print(5 % 2) # 1
19+
print(type(5 % 2)) # int
20+
21+
print(5 > 1) # True
22+
print(type(5 > 1)) # bool
23+
24+
print('5') # '5'
25+
print(type('5')) # str
26+
27+
print(5 * 2) # 10
28+
print(type(5 * 2)) # int
29+
30+
print('5' * 2) # '55'
31+
print(type('5' * 2)) # str
32+
33+
print('5' + '2') # '52'
34+
print(type('5' + '2')) # str
35+
36+
print(5 / 2) # 2.5
37+
print(type(5 / 2)) # float
38+
39+
print(5 // 2) # 2
40+
print(type(5 // 2)) # int
41+
42+
print([5, 2, 1]) # [5, 2, 1]
43+
print(type([5, 2, 1])) # list
44+
45+
print(5 in [1, 4, 6]) # False
46+
print(type(5 in [1, 4, 6])) # bool

‎Lesson-01/pe1_2.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'''
2+
3+
Introduction To Computing Using Python (Werkboek)
4+
5+
Starten met Python (Perkovic - §1.1 t/m §2.3)
6+
7+
Practice Exercise 1.2 (strings)
8+
Schrijf en evalueer Python expressies die de volgende vragen beantwoorden:
9+
10+
'''
11+
12+
# (a) Hoeveel letters zijn er in 'Supercalifragilisticexpialidocious' ?
13+
a = len('Supercalifragilisticexpialidocious')
14+
print(a) # 34
15+
16+
# (b) Komt in ' Supercalifragilisticexpialidocious' de tekst 'ice' voor?
17+
b = 'ice' in 'Supercalifragilisticexpialidocious'
18+
print(b) # True
19+
20+
# (c) Is het woord 'Antidisestablishmentarianism' langer dan
21+
# 'Honorificabilitudinitatibus' ?
22+
c = 'Antidisestablishmentarianism' > 'Honorificabilitudinitatibus'
23+
print(c) # False
24+
25+
# (d) Welke componist komt in alfabetische volgorde het eerst: 'Berlioz',
26+
# 'Borodin', 'Brian', 'Bartok', 'Bellini' 'Buxtehude', 'Bernstein'? Welke het
27+
# laatst?
28+
componists = ['Berlioz', 'Borodin', 'Brian', 'Bartok', 'Buxtehude', 'Bernstein']
29+
30+
# Eerste componist in componists in alfabetische volgorde.
31+
first = min(componists)
32+
print(first) # Bartrok
33+
34+
# Laatste componist in componists in alfabetische volgorde.
35+
last = max(componists)
36+
print(last) # Buxtehude

‎Lesson-01/pe1_3.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'''
2+
3+
Introduction To Computing Using Python (Werkboek)
4+
5+
Starten met Python (Perkovic - §1.1 t/m §2.3)
6+
7+
Practice Exercise 1.3 (statements)
8+
Schrijf Python statements die het volgende doen:
9+
10+
'''
11+
12+
# 1. Ken de waarde 6 toe aan variabele a, en waarde 7 aan variabele b.
13+
a = 6
14+
b = 7
15+
16+
# 2. Ken aan variabele c als waarde het gemiddelde van a en b toe.
17+
c = (a + b) / 2
18+
19+
# 3. Ken aan variabele inventaris een lijst van strings toe: `papier`,
20+
# `nietjes`, en `pennen`.
21+
inventaris = ['papier', 'nietjes', 'pennen']
22+
23+
# 4. Ken aan variabelen voornaam, tussenvoegsel en achternaam je eigen
24+
# naamgegevens toe.
25+
voornaam = 'Yannick'
26+
tussenvoegsel = ''
27+
achternaam = 'Thomassen'
28+
29+
# 5. Ken aan variabele mijnnaam de variabelen van opdracht 4 (met spaties er
30+
# tussen) toe.
31+
mijnnaam = voornaam = ' ' + achternaam

‎Lesson-01/pe1_4.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
3+
Introduction To Computing Using Python (Werkboek)
4+
5+
Starten met Python (Perkovic - §1.1 t/m §2.3)
6+
7+
Practice Exercise 1.4 (boolean expressions)
8+
Schrijf booleaanse expressies die van de variabelen van Practice Exercise 1_3
9+
evalueren of:
10+
11+
'''
12+
13+
# 1. 6.75 groter is dan a en kleiner dan b.
14+
a = 6
15+
b = 7
16+
17+
c = 6.75 > a and 6.75 < b
18+
print(c) # True
19+
20+
# 2. De lengte van inventaris meer dan 5 keer zo groot is als de lengte van
21+
# van variabele mijnnaam.
22+
inventaris = ['papier', 'nietjes', 'pennen']
23+
24+
voornaam = 'Yannick'
25+
achternaam = 'Thomassen'
26+
27+
mijnnaam = voornaam + ' ' + achternaam
28+
29+
d = len(inventaris) > len(mijnnaam) * 5
30+
print(d) # False
31+
32+
# 3. De lijst inventaris leeg is, of juist meer dan 10 items bevat.
33+
e = len(inventaris) == 0 or len(inventaris) > 10
34+
print(e) # False

‎Lesson-01/pe1_5.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''
2+
3+
Introduction To Computing Using Python (Werkboek)
4+
5+
Starten met Python (Perkovic - §1.1 t/m §2.3)
6+
7+
Practice Exercise 1.5 (lists)
8+
We gaan een lijst bijhouden met je favoriete artiesten. We gaan de lijst eerst
9+
creëren met 1 artiest en dan uitbreiden. Schrijf per stap een expressie om:
10+
11+
'''
12+
13+
# 1. Een nieuwe list met 1 artiest aan te maken met de naam favorieten.
14+
favorieten = ['nothing,nowhere']
15+
print(favorieten) # ['nothing,nowhere']
16+
17+
# 2. De lijst uit te breiden met een tweede artiest.
18+
favorieten.append('lil peep')
19+
print(favorieten) # ['nothing,nowhere', 'lil peep']
20+
21+
# 3. De tweede artiest de vervangen door een andere naam.
22+
favorieten[1] = 'VAGUE003'
23+
print(favorieten) # ['nothing,nowhere', 'VAGUE003']

‎Lesson-01/pe1_6.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
3+
Introduction To Computing Using Python (Werkboek)
4+
5+
Starten met Python (Perkovic - §1.1 t/m §2.3)
6+
7+
Practice Exercise 1.6 (lists)
8+
Het bereik van een lijst is het verschil tussen de grootste en het kleinste
9+
getal. Schrijf een Python expressie die het bereik van een lijst berekent. Als
10+
bijvoorbeeld variabele list bestaat uit de getallen 4, 7, -2, en 12, dan moet
11+
de expressie evalueren naar 14 (verschil tussen 12 en -2). Zorg dat de
12+
expressie altijd werkt, ook al bestaat de lijst uit andere waarden!
13+
14+
'''
15+
16+
numbers = [4, 7, -2, 12]
17+
18+
a = abs(min(numbers) - max(numbers))
19+
print(a) # 14

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /