Skip to content

Commit d4b77c1

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

25 files changed

+272
-7
lines changed

README.md

+14-4
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 **60** exercises and questions
5+
:bar_chart:  There are currently **70** exercises and questions
66

77
# Python Exercises
88

@@ -50,13 +50,17 @@
5050
|Name|Objective & Instructions|Solution|Comments|
5151
|--------|--------|------|----|
5252
| 22 times | [Exercise](exercises/hello_world/22_times.md) | | |
53+
| Variables | [Exercise](exercises/strings/variables.md) | [Solution](solutions/strings/variables.md) | |
5354
| 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) | |
5455
| 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) | |
5556
| Starts with a letter | [Exercise](exercises/strings/letter_start.md) | [Solution](solutions/strings/letter_start.md) | |
57+
| Change Strings | [Exercise](exercises/strings/change_strings.md) | [Solution](solutions/strings/change_strings.md) | |
5658
| All Digits | [Exercise](exercises/strings/all_digits.md) | [Solution](solutions/strings/all_digits.md) | |
5759
| Removing Characters | [Exercise](exercises/strings/removing_characters.md) | [Solution](solutions/strings/removing_characters.md) | |
5860
| Reverse a String | [Exercise](exercises/strings/reverse_string.md) | [Solution](solutions/strings/reverse_string.md) | |
5961
| Compress Strings | [Exercise](exercises/strings/compress_strings.md) | | |
62+
| Slicing - Level 1 | [Exercise](exercises/strings/slicing_lvl_1.md) | [Solution](solutions/strings/slicing_lvl_1.md) | |
63+
| Slicing - Level 2 | [Exercise](exercises/strings/slicing_lvl_2.md) | [Solution](solutions/strings/slicing_lvl_2.md) | |
6064

6165
## Numbers
6266

@@ -68,7 +72,7 @@
6872
| Bases | [Exercise](exercises/numbers/bases.md) | [Solution](solutions/numbers/bases.md) | |
6973
| Palindrome | [Exercise](exercises/numbers/palindrome.md) | [Solution](solutions/numbers/palindrome.md) | |
7074

71-
## Lists
75+
## Lists & Tuples
7276

7377
|Name|Objective & Instructions|Solution|Comments|
7478
|--------|--------|------|----|
@@ -77,12 +81,17 @@
7781
| Length | [Exercise](exercises/hello_world/length.md) | | |
7882
| Min Max | [Exercise](exercises/lists/min_max.md) | [Solution](solutions/lists/min_max.md) | |
7983
| Three Biggest Items | [Exercise](exercises/lists/three_biggest_items.md) | [Solution](solutions/lists/three_biggest_items.md) | |
80-
| What is the result? | [Exercise](exercises/lists/what_is_the_result.md) | [Solution](solutions/lists/what_is_the_result.md) | |
84+
| What is the result? - Level 1 | [Exercise](exercises/lists/what_is_the_result_lvl_1.md) | [Solution](solutions/lists/what_is_the_result_lvl_1.md) | |
85+
| What is the result? - Level 2 | [Exercise](exercises/lists/what_is_the_result_lvl_2.md) | [Solution](solutions/lists/what_is_the_result_lvl_2.md) | |
8186

8287
## Loops
8388

8489
|Name|Objective & Instructions|Solution|Comments|
8590
|--------|--------|------|----|
91+
| Break Out | [Exercise](exercises/loops/break_out.md) | [Solution](solutions/loops/break_out.md) | |
92+
| Break Out 2 | [Exercise](exercises/loops/break_out.md) | [Solution](solutions/loops/break_out.md) | |
93+
| Every character | [Exercise](exercises/loops/every_char.md) | [Solution](solutions/loops/every_char.md) | |
94+
| Stream of Numbers | [Exercise](exercises/loops/numbers_stream.md) | [Solution](solutions/loops/numbers_stream.md) | |
8695
| Refactor-1 | [Exercise](exercises/loops/refactor_1.md) | [Solution](solutions/loops/refactor_1.py) | |
8796

8897
## Functions
@@ -123,7 +132,8 @@
123132
|Name|Objective & Instructions|Solution|Comments|
124133
|--------|--------|------|----|
125134
| Dividing by Zero | [Exercise](exercises/exceptions/divide_by_zero.md) | [Solution](solutions/exceptions/divide_by_zero.md) | |
126-
| What exception is raised? | [Exercise](exercises/exceptions/what_exception_is_raised.md) | [Solution](solutions/exceptions/what_exception_is_raised.md) | |
135+
| What exception is raised? - Level 1 | [Exercise](exercises/exceptions/what_exception_is_raised_lvl_1.md) | [Solution](solutions/exceptions/what_exception_is_raised_lvl_1.md) | |
136+
| What exception is raised? - Level 2 | [Exercise](exercises/exceptions/what_exception_is_raised_lvl_2.md) | [Solution](solutions/exceptions/what_exception_is_raised_lvl_2.md) | |
127137

128138
## Regex
129139

exercises/exceptions/what_exception_is_raised.md renamed to exercises/exceptions/what_exception_is_raised_lvl_1.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## What Exception is Raised?
1+
## What Exception is Raised? - Level 1
22

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## What Exception is Raised? - Level 2
2+
3+
For each of the following statement, specify what exception will be raised
4+
5+
1. `chars = "abc";chars[0]='h'`
6+
7+
### Solution
8+
9+
1. TypeError
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## What is the result?
2+
3+
1. What is the result of the following block of code?
4+
5+
```python
6+
x = ['a', 'b', 'c']
7+
for i in x:
8+
if i == 'b':
9+
x = ['z', 'y']
10+
print(i)
11+
```
12+
13+
### Solution
14+
15+
Click [here](solutions/lists/what_is_the_result_lvl_1.md) to view the solution.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## What is the result? - Level 2
2+
3+
1. What is the result of the following block of code?
4+
5+
```python
6+
x = ['a', 'b', 'c']
7+
for i in x:
8+
if i == 'b':
9+
x = ['z', 'y']
10+
print(i)
11+
```
12+
13+
### Solution
14+
15+
Click [here](solutions/lists//what_is_the_result_lvl_2.md) to view the solution.

exercises/loops/break_out.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Break Out
2+
3+
Write a loop that will keep reversing user's input until he enters the letter 'q' to quit
4+
5+
## Solution
6+
7+
Click [here](solutions/loops/break_out.md) to view the solution.

exercises/loops/break_out_2.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Break Out 2
2+
3+
Iterate over a given list of numbers and break out of it if one the numbers is 2 or 4. If you didn't any of these numbers, print a message saying so.
4+
5+
### Solution
6+
7+
Click [here](solutions/loops/break_out_2.md) to view the solution.

exercises/loops/every_char.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Every Character
2+
3+
Given a variable of a string, print character of the string on its own line.
4+
5+
### Solution
6+
7+
Click [here](solutions/loops/every_char.md) to view the solution.

exercises/loops/numbers_stream.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Stream of Numbers
2+
3+
1. Print the numbers between 0 and 10
4+
2. Print the number between 0 and -10
5+
6+
### Solution
7+
8+
Click [here](solutions/loops/numbers_stream.md) to view the solution.

exercises/strings/change_strings.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Change Strings
2+
3+
Modify the string "cat" to "bat"
4+
5+
### Solution
6+
7+
Click [here](soltuions/strings/change_strings.md) to view the solution.

exercises/strings/slicing_lvl_1.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Slicing - Level 1
2+
3+
What is the result of each of the following statements if `x = 'abcdefgh'`
4+
5+
1. `x[:]`
6+
2. `x[2:]`
7+
3. `x[2:2]`
8+
4. `x[2:3]`
9+
5. `x[-1:]`
10+
11+
### Solution
12+
13+
Click [here](solutions/strings/slicing_lvl_1.md) to view the solution.

exercises/strings/slicing_lvl_2.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Slicing - Level 2
2+
3+
What is the result of each of the following statements if `x = 'abcdefgh'`
4+
5+
1. `x[-1:-2]`
6+
2. `x[3:-1]`
7+
3. `x[::1]`
8+
4. `x[::3]`
9+
5. `x[1:2:3]`
10+
6. `x[::-1]`
11+
7. `x[1::-1]`
12+
13+
### Solution
14+
15+
Click [here](solutions/strings/slicing_lvl_2.md) to view the solution.

exercises/strings/variables.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Strings & Variables
2+
3+
Using the variable `fruit = "strawberry"` print the following:
4+
5+
1. `Best fruit is: strawberry`
6+
2. `Yes, strawberry. Only strawberry`
7+
3. `Hello, my name is Mr. Strawberry`
8+
4. `fruit = 'strawberry'`
9+
10+
### Solution
11+
12+
Click [here](solutions/strings/variables.md) to view the solution.

solutions/exceptions/what_exception_is_raised.md renamed to solutions/exceptions/what_exception_is_raised_lvl_1.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## What Exception is Raised?
1+
## What Exception is Raised? - Level 1
22

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## What Exception is Raised? - Level 2
2+
3+
For each of the following statement, specify what exception will be raised
4+
5+
1. `chars = "abc";chars[0]='h'`
6+
7+
### Solution
8+
9+
1. TypeError
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## What is the result?
2+
3+
1. `'x = 'pizza,';print(x)`
4+
2. `x = ('pizza',);print(x)`
5+
3. `x = ('pizza');print(x)`
6+
4. `x = 'pizza', 'pasta';print(x)`
7+
8+
### Solution
9+
10+
1. `pizza,`
11+
2. `('pizza')`
12+
3. `pizza`
13+
4. `('pizza', 'pasta')`

solutions/lists/what_is_the_result.md renamed to solutions/lists/what_is_the_result_lvl_2.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## What is the result?
1+
## What is the result? - Level 2
22

33
1. What is the result of the following block of code?
44

solutions/loops/break_out.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Break Out
2+
3+
Write a loop that will keep reversing user's input until he enters the letter 'q' to quit
4+
5+
## Solution
6+
7+
```python
8+
while True:
9+
ans = input("Please insert a string to reverse: ")
10+
if ans == 'q':
11+
break
12+
print(ans[::-1])
13+
```

solutions/loops/break_out_2.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Break Out 2
2+
3+
Iterate over a given list of numbers and break out of it if one the numbers is 2 or 4. If you didn't any of these numbers, print a message saying so.
4+
5+
### Solution
6+
7+
```python
8+
for i in li:
9+
if i == 2 or i == 4:
10+
print("Found it!")
11+
break
12+
else:
13+
print("Didn't find 2 nor 4")
14+
```

solutions/loops/every_char.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Every Character
2+
3+
Given a variable of a string, print character of the string on its own line.
4+
5+
### Solution
6+
7+
```python
8+
string = "python"
9+
for char in string:
10+
print(char)
11+
````

solutions/loops/numbers_stream.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Stream of Numbers
2+
3+
1. Print the numbers between 0 and 10
4+
2. Print the number between 0 and -10
5+
6+
### Solution
7+
8+
1.
9+
10+
```python
11+
for i in range(0, 11):
12+
print(i)
13+
```
14+
15+
2.
16+
17+
```python
18+
for i in range (0, -11, -1):
19+
print(i)
20+
```

solutions/strings/change_strings.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Change Strings
2+
3+
Modify the string "cat" to "bat"
4+
5+
### Soltuion
6+
7+
`"cat".replace("c", "b")` OR `"b" + "cat"[1:]`

solutions/strings/slicing_lvl_1.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Slicing - Level 1
2+
3+
What is the result of each of the following statements if `x = 'abcdefgh'`
4+
5+
1. `x[:]`
6+
2. `x[2:]`
7+
3. `x[2:2]`
8+
4. `x[2:3]`
9+
5. `x[-1:]`
10+
11+
### Solution
12+
13+
1. `'abcdefgh'`
14+
2. `'cdefgh'`
15+
3. `''`
16+
4. `'c'`
17+
5. `'h'`

solutions/strings/slicing_lvl_2.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Slicing - Level 2
2+
3+
What is the result of each of the following statements if `x = 'abcdefgh'`
4+
5+
1. `x[-1:-2]`
6+
2. `x[3:-1]`
7+
3. `x[::1]`
8+
4. `x[::3]`
9+
5. `x[1:2:3]`
10+
6. `x[::-1]`
11+
7. `x[1::-1]`
12+
13+
### Solution
14+
15+
1. `''`
16+
2. `'defg'`
17+
3. `'abcdefgh'`
18+
4. `'adg'`
19+
5. `'b'`
20+
6. `'hgfedcba'`
21+
7. `'ba'`

solutions/strings/variables.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Strings & Variables
2+
3+
Using the variable `fruit = "strawberry"` print the following:
4+
5+
1. `Best fruit is: strawberry`
6+
2. `Yes, strawberry. Only strawberry`
7+
3. `Hello, my name is Mr. Strawberry`
8+
4. `fruit = 'strawberry'`
9+
10+
### Solution
11+
12+
1. `print(f'Best fruit is: {fruit}')`
13+
2. `print(f'Yes, {fruit}. Only {fruit}')`
14+
3. `print(f'Hello, my name is Mr. {fruit.capitalize()}')`
15+
4. `print(f'{fruit = }')` # Supported only using Python 3.8+

0 commit comments

Comments
 (0)