forked from A-zhudong/python-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
abregman
committed
Apr 23, 2022
1 parent
54403cb
commit d4b77c1
Showing
25 changed files
with
272 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...es/exceptions/what_exception_is_raised.md → ...eptions/what_exception_is_raised_lvl_1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## What Exception is Raised? - Level 2 | ||
|
||
For each of the following statement, specify what exception will be raised | ||
|
||
1. `chars = "abc";chars[0]='h'` | ||
|
||
### Solution | ||
|
||
1. TypeError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## What is the result? | ||
|
||
1. What is the result of the following block of code? | ||
|
||
```python | ||
x = ['a', 'b', 'c'] | ||
for i in x: | ||
if i == 'b': | ||
x = ['z', 'y'] | ||
print(i) | ||
``` | ||
|
||
### Solution | ||
|
||
Click [here](solutions/lists/what_is_the_result_lvl_1.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## What is the result? - Level 2 | ||
|
||
1. What is the result of the following block of code? | ||
|
||
```python | ||
x = ['a', 'b', 'c'] | ||
for i in x: | ||
if i == 'b': | ||
x = ['z', 'y'] | ||
print(i) | ||
``` | ||
|
||
### Solution | ||
|
||
Click [here](solutions/lists//what_is_the_result_lvl_2.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Break Out | ||
|
||
Write a loop that will keep reversing user's input until he enters the letter 'q' to quit | ||
|
||
## Solution | ||
|
||
Click [here](solutions/loops/break_out.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Break Out 2 | ||
|
||
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. | ||
|
||
### Solution | ||
|
||
Click [here](solutions/loops/break_out_2.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Every Character | ||
|
||
Given a variable of a string, print character of the string on its own line. | ||
|
||
### Solution | ||
|
||
Click [here](solutions/loops/every_char.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Stream of Numbers | ||
|
||
1. Print the numbers between 0 and 10 | ||
2. Print the number between 0 and -10 | ||
|
||
### Solution | ||
|
||
Click [here](solutions/loops/numbers_stream.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Change Strings | ||
|
||
Modify the string "cat" to "bat" | ||
|
||
### Solution | ||
|
||
Click [here](soltuions/strings/change_strings.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Slicing - Level 1 | ||
|
||
What is the result of each of the following statements if `x = 'abcdefgh'` | ||
|
||
1. `x[:]` | ||
2. `x[2:]` | ||
3. `x[2:2]` | ||
4. `x[2:3]` | ||
5. `x[-1:]` | ||
|
||
### Solution | ||
|
||
Click [here](solutions/strings/slicing_lvl_1.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Slicing - Level 2 | ||
|
||
What is the result of each of the following statements if `x = 'abcdefgh'` | ||
|
||
1. `x[-1:-2]` | ||
2. `x[3:-1]` | ||
3. `x[::1]` | ||
4. `x[::3]` | ||
5. `x[1:2:3]` | ||
6. `x[::-1]` | ||
7. `x[1::-1]` | ||
|
||
### Solution | ||
|
||
Click [here](solutions/strings/slicing_lvl_2.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Strings & Variables | ||
|
||
Using the variable `fruit = "strawberry"` print the following: | ||
|
||
1. `Best fruit is: strawberry` | ||
2. `Yes, strawberry. Only strawberry` | ||
3. `Hello, my name is Mr. Strawberry` | ||
4. `fruit = 'strawberry'` | ||
|
||
### Solution | ||
|
||
Click [here](solutions/strings/variables.md) to view the solution. |
2 changes: 1 addition & 1 deletion
2
...ns/exceptions/what_exception_is_raised.md → ...eptions/what_exception_is_raised_lvl_1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## What Exception is Raised? - Level 2 | ||
|
||
For each of the following statement, specify what exception will be raised | ||
|
||
1. `chars = "abc";chars[0]='h'` | ||
|
||
### Solution | ||
|
||
1. TypeError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## What is the result? | ||
|
||
1. `'x = 'pizza,';print(x)` | ||
2. `x = ('pizza',);print(x)` | ||
3. `x = ('pizza');print(x)` | ||
4. `x = 'pizza', 'pasta';print(x)` | ||
|
||
### Solution | ||
|
||
1. `pizza,` | ||
2. `('pizza')` | ||
3. `pizza` | ||
4. `('pizza', 'pasta')` |
2 changes: 1 addition & 1 deletion
2
solutions/lists/what_is_the_result.md → solutions/lists/what_is_the_result_lvl_2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## What is the result? | ||
## What is the result? - Level 2 | ||
|
||
1. What is the result of the following block of code? | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Break Out | ||
|
||
Write a loop that will keep reversing user's input until he enters the letter 'q' to quit | ||
|
||
## Solution | ||
|
||
```python | ||
while True: | ||
ans = input("Please insert a string to reverse: ") | ||
if ans == 'q': | ||
break | ||
print(ans[::-1]) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Break Out 2 | ||
|
||
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. | ||
|
||
### Solution | ||
|
||
```python | ||
for i in li: | ||
if i == 2 or i == 4: | ||
print("Found it!") | ||
break | ||
else: | ||
print("Didn't find 2 nor 4") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Every Character | ||
|
||
Given a variable of a string, print character of the string on its own line. | ||
|
||
### Solution | ||
|
||
```python | ||
string = "python" | ||
for char in string: | ||
print(char) | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## Stream of Numbers | ||
|
||
1. Print the numbers between 0 and 10 | ||
2. Print the number between 0 and -10 | ||
|
||
### Solution | ||
|
||
1. | ||
|
||
```python | ||
for i in range(0, 11): | ||
print(i) | ||
``` | ||
|
||
2. | ||
|
||
```python | ||
for i in range (0, -11, -1): | ||
print(i) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Change Strings | ||
|
||
Modify the string "cat" to "bat" | ||
|
||
### Soltuion | ||
|
||
`"cat".replace("c", "b")` OR `"b" + "cat"[1:]` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Slicing - Level 1 | ||
|
||
What is the result of each of the following statements if `x = 'abcdefgh'` | ||
|
||
1. `x[:]` | ||
2. `x[2:]` | ||
3. `x[2:2]` | ||
4. `x[2:3]` | ||
5. `x[-1:]` | ||
|
||
### Solution | ||
|
||
1. `'abcdefgh'` | ||
2. `'cdefgh'` | ||
3. `''` | ||
4. `'c'` | ||
5. `'h'` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Slicing - Level 2 | ||
|
||
What is the result of each of the following statements if `x = 'abcdefgh'` | ||
|
||
1. `x[-1:-2]` | ||
2. `x[3:-1]` | ||
3. `x[::1]` | ||
4. `x[::3]` | ||
5. `x[1:2:3]` | ||
6. `x[::-1]` | ||
7. `x[1::-1]` | ||
|
||
### Solution | ||
|
||
1. `''` | ||
2. `'defg'` | ||
3. `'abcdefgh'` | ||
4. `'adg'` | ||
5. `'b'` | ||
6. `'hgfedcba'` | ||
7. `'ba'` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Strings & Variables | ||
|
||
Using the variable `fruit = "strawberry"` print the following: | ||
|
||
1. `Best fruit is: strawberry` | ||
2. `Yes, strawberry. Only strawberry` | ||
3. `Hello, my name is Mr. Strawberry` | ||
4. `fruit = 'strawberry'` | ||
|
||
### Solution | ||
|
||
1. `print(f'Best fruit is: {fruit}')` | ||
2. `print(f'Yes, {fruit}. Only {fruit}')` | ||
3. `print(f'Hello, my name is Mr. {fruit.capitalize()}')` | ||
4. `print(f'{fruit = }')` # Supported only using Python 3.8+ |