Skip to content

Commit 2673ad5

Browse files
author
abregman
committed
Add a couple of exercises
1 parent 81daa51 commit 2673ad5

File tree

12 files changed

+90
-5
lines changed

12 files changed

+90
-5
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44

55
|Name|Objective & Instructions|Solution|Comments|
66
|--------|--------|------|----|
7-
| Hello World! | [Exercise](exercises/hello_world/hello_world.md) | [Solution](solutions/hello_world/hello_world.md) | |
8-
| 22 times | [Exercise](exercises/hello_world/22_times.md) | [Solution](solutions/hello_world/22_times.md) | |
7+
| Hello World! | [Exercise](exercises/hello_world/hello_world.md) | | |
8+
| 22 times | [Exercise](exercises/hello_world/22_times.md) | | |
9+
| Length | [Exercise](exercises/hello_world/length.md) | | |
10+
11+
## Data Types
12+
13+
|Name|Objective & Instructions|Solution|Comments|
14+
|--------|--------|------|----|
15+
| Data Types? I know a few | [Exercise](exercises/data_types/I_know_a_few.md) | [Solution](solutions/exceptions/I_know_a_few.md) | |
16+
| Choose a Data Type - level 1 | [Exercise](exercises/data_types/choose_datatype_level_1.md) | [Solution](solutions/data_types/choose_datatype_level_1.md) | |
17+
| Choose a Data Type - level 2 | [Exercise](exercises/data_types/choose_datatype_level_2.md) | [Solution](solutions/data_types/choose_datatype_level_2.md) | |
918

1019
## Loops
1120

@@ -31,3 +40,17 @@
3140
|Name|Objective & Instructions|Solution|Comments|
3241
|--------|--------|------|----|
3342
| Dividing by Zero | [Exercise](exercises/exceptions/divide_by_zero.md) | [Solution](solutions/exceptions/divide_by_zero.md) | |
43+
44+
## Files
45+
46+
|Name|Objective & Instructions|Solution|Comments|
47+
|--------|--------|------|----|
48+
| Read a File | [Exercise](exercises/files/read_file.md) | | |
49+
50+
## Operating Systems
51+
52+
|Name|Objective & Instructions|Solution|Comments|
53+
|--------|--------|------|----|
54+
| File exists | [Exercise](exercises/os/file_exists.md) | | |
55+
| Print all the files in a directory | [Exercise](exercises/os/print_all_files_in_dir.md) | | |
56+

exercises/data_types/I_know_a_few.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Data Types? I Know a Few
2+
3+
Which data types are you familiar with?
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Choose a Data Type
2+
3+
For each of the following scenarios, choose the data type you would use
4+
5+
1. Storing the string "Hello World"
6+
2. Mapping between fruit names and their color
7+
3. A collection of numbers (sorted)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Choose a Data Type - Level 2
2+
3+
Choose a data type in each of the following scenarios:
4+
5+
1. A class to represent a mushroom (name and whether it's poisonous) without custom methods

exercises/files/read_file.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Read a File
2+
3+
Write a code that will read a file and print all its content

exercises/hello_world/length.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Length
2+
3+
1. How to print the length of the string 'abcd' ?
4+
2. How to print the length of the variable x (x is the list [5, 30 ,2]) ?
5+
3. What would be the length of following dictionary {'x': 3, 'y': 3} ?
6+
4. What would be the length of the tuple ('x', 'y') ?

exercises/loops/refactor_1.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Refactor the following code
55
```python
66
from collections import namedtuple
77

8-
Mushroom = collections.nametuple('Mushroom', ['name', 'poisonous'])
8+
Mushroom = namedtuple('Mushroom', ['name', 'poisonous'])
99

10-
mushrooms = [Mushroom('Portabello', false), Mushroom('Oyster', false),
11-
Mushroom('Death Cap', true)]
10+
mushrooms = [Mushroom('Portabello', False), Mushroom('Oyster', False),
11+
Mushroom('Death Cap', True)]
1212
i = 0
1313

1414
for mushroom in mushrooms:

exercises/os/file_exists.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## File Exists
2+
3+
For a given file, check if the file exists
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Print all the files in a directory
2+
3+
Without using `os.walk` or `os.tree`, print all the files in a given directory (including any nested directories)

solutions/data_types/I_know_a_few.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Data Types? I know a few
2+
3+
The built-in data types:
4+
* dict: {'x': 1, 'y': 2}
5+
* list: [1, 2]
6+
* set: {'x', 'y'}
7+
* frozenset: {'x', 'y'}
8+
* str: 'x, y'
9+
* tuple: ('x', 'y')
10+
11+
There are also modules which are part of the standard library and provide their own data types:
12+
* datetime
13+
* collections.namedtuple
14+
* collections.abc
15+
* bisect
16+
...
17+
18+
The list is quite long and be seen fully [here](https://docs.python.org/3/library/datatypes.html)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Choose a Data Type
2+
3+
For each of the following scenarios, choose the data type you would use
4+
5+
1. Storing the string "Hello World" - str
6+
2. Mapping between fruit names and their color - dict: {'apple': 'red'}
7+
3. A collection of numbers (sorted) - list: [1, 5, 6]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Choose a Data Type - Level 2
2+
3+
Choose a data type in each of the following scenarios:
4+
5+
1. A class to represent a mushroom (name and whether it's poisonous) without custom methods
6+
7+
namedtuple: `Mushroom = collection.namedtuple('Mushroom', ['Oyster', False])`

0 commit comments

Comments
 (0)