Skip to content

Commit 54403cb

Browse files
author
abregman
committed
Add a couple of exercises
1 parent acdfe31 commit 54403cb

21 files changed

+272
-30
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
:information_source:  This repo contains questions and exercises to learn and practice Python
44

5-
:bar_chart:  There are currently **53** exercises and questions
5+
:bar_chart:  There are currently **60** exercises and questions
66

77
# Python Exercises
88

@@ -43,13 +43,15 @@
4343
|Name|Objective & Instructions|Solution|Comments|
4444
|--------|--------|------|----|
4545
| True or False? | [Exercise](exercises/booleans/true_or_false.md) | [Solution](solutions/booleans/true_or_false.md) | |
46+
| Conversion | [Exercise](exercises/booleans/conversion.md) | [Solution](solutions/booleans/conversion.md) | |
4647

4748
## Strings
4849

4950
|Name|Objective & Instructions|Solution|Comments|
5051
|--------|--------|------|----|
5152
| 22 times | [Exercise](exercises/hello_world/22_times.md) | | |
52-
| What is the result? | [Exercise](exercises/strings/what_is_the_result.md) | [Solution](solutions/strings/what_is_the_result.md) | |
53+
| What is the result? - Level 1 | [Exercise](exercises/strings/what_is_the_result_lvl_1.md) | [Solution](solutions/strings/what_is_the_result_lvl_1.md) | |
54+
| What is the result? - Level 2 | [Exercise](exercises/strings/what_is_the_result_lvl_2.md) | [Solution](solutions/strings/what_is_the_result_lvl_2.md) | |
5355
| Starts with a letter | [Exercise](exercises/strings/letter_start.md) | [Solution](solutions/strings/letter_start.md) | |
5456
| All Digits | [Exercise](exercises/strings/all_digits.md) | [Solution](solutions/strings/all_digits.md) | |
5557
| Removing Characters | [Exercise](exercises/strings/removing_characters.md) | [Solution](solutions/strings/removing_characters.md) | |
@@ -61,6 +63,9 @@
6163
|Name|Objective & Instructions|Solution|Comments|
6264
|--------|--------|------|----|
6365
| What is the result? | [Exercise](exercises/numbers/what_is_the_result.md) | [Solution](solutions/numbers/what_is_the_result.md) | |
66+
| Operations - Level 1 | [Exercise](exercises/numbers/operations_lvl_1.md) | [Solution](solutions/numbers/operations_lvl_1.md) | |
67+
| Operations - Level 2 | [Exercise](exercises/numbers/operations_lvl_2.md) | [Solution](solutions/numbers/operations_lvl_2.md) | |
68+
| Bases | [Exercise](exercises/numbers/bases.md) | [Solution](solutions/numbers/bases.md) | |
6469
| Palindrome | [Exercise](exercises/numbers/palindrome.md) | [Solution](solutions/numbers/palindrome.md) | |
6570

6671
## Lists
@@ -145,6 +150,8 @@
145150

146151
|Name|Objective & Instructions|Solution|Comments|
147152
|--------|--------|------|----|
153+
| If True | [Exercise](exercises/improve_the_code/if_true.md) | [Solution](solutions/improve_the_code/if_true.md) | |
154+
| Walrus | [Exercise](exercises/improve_the_code/walrus.md) | [Solution](solutions/improve_the_code/walrus.md) | |
148155
| Vowel Letters | [Exercise](exercises/improve_the_code/vowel_letters.md) | [Solution](solutions/improve_the_code/vowel_letters.md) | |
149156

150157
## Misc

exercises/booleans/conversion.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Conversion
2+
3+
What is the result of each of the following statements?
4+
5+
1. `int(False)`
6+
2. `int(True)`
7+
3. `bool(0)`
8+
4. `bool(1)`
9+
5. `True + 2`
10+
6. `float(True)`
11+
12+
## Solution
13+
14+
Click [here](solutions/booleans/conversion.md) to view the solution

exercises/exceptions/what_exception_is_raised.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ For each of the following statement, specify what exception will be raised
44

55
1. `'two' > 1`
66
2. `ans = x + y`
7+
3. `chars = 'abc'; chars[5]`
8+
9+
### Solution
10+
11+
Click [here](solutions/exceptions/what_exception_is_raised.md) to view the solution.

exercises/improve_the_code/if_true.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## If True
2+
3+
Improve the following block of code:
4+
5+
```
6+
y = 0
7+
x = False
8+
9+
if x == True:
10+
y = y + 1
11+
if x == False:
12+
y = y + 2
13+
```
14+
15+
### Solution
16+
17+
Click [here](solutions/improve_the_code/if_true.md) to view the solution

exercises/improve_the_code/walrus.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Walrus
2+
3+
Modify the following code so it will use the walrus operator:
4+
5+
```python
6+
x = 50
7+
y = x - 20
8+
if y == 30:
9+
print("super")
10+
```
11+
12+
### Solution
13+
14+
Click [here](solutions/improve_the_code/walrus.md) to view the solution

exercises/numbers/bases.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Bases
2+
3+
What is the result of each of the following statements:
4+
5+
1. `0b10 + 0b10`
6+
2. `0o10 ** 3`
7+
3. `0x10 & 2`
8+
9+
### Solution
10+
11+
Click [here](solutions/numbers/bases.md) to view the solution

exercises/numbers/operations_lvl_1.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Operations
2+
3+
What is the result of the following operations in Python?
4+
5+
1. `4 / 3`
6+
2. `4 / 0`
7+
3. `4 // 3`
8+
4. `4 // 0`
9+
10+
### Solution
11+
12+
Click [here](solutions/numbers/operations.md) to view the solution

exercises/numbers/operations_lvl_2.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Operations - Level 2
2+
3+
What will the following block of code will print?
4+
5+
```
6+
x = 3
7+
x -= 1
8+
x += 5
9+
x **= 2.0
10+
x += 2 * (3 + 1)
11+
```
12+
13+
### Solution
14+
15+
Click [here](solutions/numbers/operations_lvl_2.md) to view the solution

exercises/strings/what_is_the_result.md

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## What is the result? - Level 1
2+
3+
What is the result of each of the following statements?
4+
5+
1. `"abc"*3`
6+
2. `"abc"*2.5`
7+
3. `"abc"*2.0`
8+
4. `"abc"*True`
9+
5. `"abc"*False`
10+
6. `print("xy\tz")`
11+
7. `print("xy\"z\'")`
12+
8. `"qwer" "xyz"`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## What is the result? - Level 2
2+
3+
What is the result of each of the following statements?
4+
5+
1. `"123456"[0]`
6+
2. `"123456"[-1]`
7+
3. `print("\\a\\b\a\c")`
8+
9+
### Solution
10+
11+
Click [here](solutions/strings/what_is_the_result_lvl_2.md) to view the solution

solutions/booleans/conversion.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Conversion
2+
3+
What is the result of each of the following statements?
4+
5+
1. `int(False)`
6+
2. `int(True)`
7+
3. `bool(0)`
8+
4. `bool(1)`
9+
5. `True + 2`
10+
6. `float(True)`
11+
12+
## Solution
13+
14+
1. `0`
15+
2. `1`
16+
3. `False`
17+
4. `True`
18+
5. `3`
19+
6. `1.0`

solutions/exceptions/what_exception_is_raised.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22

33
For each of the following statement, specify what exception will be raised
44

5-
1. `'two' > 1` - TypeError
6-
2. `ans = x + y` - NameError
5+
1. `'two' > 1`
6+
2. `ans = x + y`
7+
3. `chars = 'abc'; chars[5]`
8+
9+
### Solution
10+
11+
1. TypeError
12+
2. NameError
13+
3. IndexError

solutions/improve_the_code/if_true.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## If True
2+
3+
Improve the following block of code:
4+
5+
```
6+
y = 0
7+
x = False
8+
9+
if x == True:
10+
y = y + 1
11+
if x == False:
12+
y = y + 2
13+
```
14+
15+
### Solution
16+
17+
```
18+
x = False
19+
if x:
20+
y = 1
21+
else:
22+
y = 2
23+
```

solutions/improve_the_code/walrus.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Walrus
2+
3+
Modify the following code so it will use the walrus operator:
4+
5+
```python
6+
x = 50
7+
y = x - 20
8+
if y == 30:
9+
print("super")
10+
```
11+
12+
### Solution
13+
14+
```python
15+
x = 50
16+
if y := x - 20 == 30:
17+
print("super")
18+
```

solutions/numbers/bases.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Bases
2+
3+
What is the result of each of the following statements:
4+
5+
1. `0b10 + 0b10`
6+
2. `0o10 ** 3`
7+
3. `0x10 & 2`
8+
9+
### Solution
10+
11+
1. `4`
12+
2. `512`
13+
3. `0`

solutions/numbers/operations_lvl_1.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Operations
2+
3+
What is the result of the following operations in Python?
4+
5+
1. `4 / 3`
6+
2. `4 // 3`
7+
3. `4 * 3`
8+
4. `4 ** 3`
9+
5. `4 *** 3`
10+
6. `4 % 3`
11+
12+
### Solution
13+
14+
1. `1.333333`
15+
2. `1`
16+
3. `12`
17+
4. `64`
18+
5. invalid syntax :)
19+
6. `1`

solutions/numbers/operations_lvl_2.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Operations - Level 2
2+
3+
What will the following block of code will print?
4+
5+
```
6+
x = 3
7+
x -= 1
8+
x += 5
9+
x **= 2.0
10+
x += 2 * (3 + 1)
11+
```
12+
13+
### Solution
14+
15+
`57.0`

solutions/strings/what_is_the_result.md

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## What is the result? - Level 1
2+
3+
What is the result of each of the following statements?
4+
5+
1. `"abc"*3`
6+
2. `"abc"*2.5`
7+
3. `"abc"*2.0`
8+
4. `"abc"*True`
9+
5. `"abc"*False`
10+
6. `print("xy\tz")`
11+
7. `print("xy\"z\'")`
12+
8. `"qwer" "xyz"`
13+
14+
### Solution
15+
16+
1. `abcabcabc`
17+
2. `TypeError`
18+
3. `TypeError`
19+
4. `"abc"`
20+
5. `""`
21+
6. `xy z`
22+
7. `xy"z'`
23+
8. `'qwerxyz'`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## What is the result? - Level 2
2+
3+
What is the result of each of the following statements?
4+
5+
1. `"123456"[0]`
6+
2. `"123456"[-1]`
7+
3. `print("\\a\\b\a\c")`
8+
9+
### Solution
10+
11+
1. `'1'`
12+
2. `'6'`
13+
3. `\a\b\c`

0 commit comments

Comments
 (0)