Skip to content

Commit 3d17488

Browse files
author
Kristian Rother
committed
clean up indexing chapters
1 parent c1d457e commit 3d17488

File tree

9 files changed

+156
-187
lines changed

9 files changed

+156
-187
lines changed

challenges/ctree.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Christmas Tree
2-
==============
1+
Star Tree
2+
=========
33

44
**🎯 Write a program that outputs the following image:**
55

@@ -11,3 +11,8 @@ Christmas Tree
1111
*******
1212
*********
1313
***********
14+
15+
.. hint::
16+
17+
You don't need to come up with an elegant solution right aways.
18+
For your first implementation, a straightforward solution is good enough.

data_structures/dictionaries.md

Lines changed: 0 additions & 69 deletions
This file was deleted.

data_structures/indexing.rst

Lines changed: 0 additions & 114 deletions
This file was deleted.

first_steps/dictionaries.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ area topic
1111
⚙ define a dictionary
1212
⚙ look up values of a dictionary
1313
🔀 iterate through a list of dictionary keys
14+
🔀 use lists as dictionary values
15+
🐞 fix errors in dictionary definitions
1416
🐞 fix index errors
1517
======= ====================================
1618

@@ -73,9 +75,40 @@ Improve the receipt assistant from the previous chapter
7375
so that it uses a dictionary of prices.
7476

7577

78+
Exercise 5: Traveler
79+
--------------------
80+
81+
The following program allows you to travel from one city to the next.
82+
Unfortunately, it contains **five bugs**. Find and fix them.
83+
84+
.. code:: python3
85+
86+
cities = {
87+
"New York": ["Tokyo", "Delhi", "London"],
88+
"Poznan": ["London", "Berlin"],
89+
"London": ["New York", "Poznan"]
90+
"Berlin": ["Tokyo", "Poznan"],
91+
"Tokyo": ["New York" "Berlin"],
92+
"Delhi": ["Katmandu"]
93+
}
94+
95+
location = "Berlin"
96+
print "\nYour task: fly to Katmandu\n"
97+
98+
while location in cities and location == 'Katmandu':
99+
print(f"You are in {location}")
100+
101+
print("There are flights to ", cities["location"])
102+
location = input("Where would you like to travel?")
103+
104+
print("You have reached your destination")
105+
106+
76107
Reflection Questions
77108
--------------------
78109

79110
- How can you create a dictionary?
111+
- What data types can you use as keys of a dictionary?
112+
- What data types can you use as values of a dictionary?
80113
- How can you modify values in a dictionary?
81114
- Is it possible to run a for loop over a dictionary?
File renamed without changes.

first_steps/indexing.rst

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
Block Cipher
3+
============
4+
5+
In this chapter you will:
6+
-------------------------
7+
8+
======= ====================================
9+
area topic
10+
======= ====================================
11+
🚀 implement a transposition cipher
12+
⚙ slice lists and strings
13+
💡 use the ``join`` method of the ``string`` data type
14+
🔀 use a loop variable for indexing
15+
======= ====================================
16+
17+
18+
Indexing and Slicing
19+
--------------------
20+
21+
Strings and lists are both ordered sequences of elements.
22+
In both, you can address elements by their position.
23+
However, Python is counting differently than humans:
24+
25+
.. figure:: indexing.png
26+
:alt: Indexing
27+
28+
29+
Exercise 1: Indexing lists
30+
--------------------------
31+
32+
What do the following expressions result in?
33+
34+
.. code:: python3
35+
36+
numbers = [1, 4, 9, 16, 25, 36]
37+
38+
numbers[4]
39+
movies[0]
40+
movies[-1]
41+
numbers[-3]
42+
43+
44+
Exercise 2: Slicing strings
45+
---------------------------
46+
47+
What do the following commands result in?
48+
49+
name = "hello world"
50+
51+
name[5:]
52+
name[5:10]
53+
name[:10:2]
54+
numbers[2:-2]
55+
numbers[::2]
56+
57+
58+
Exercise 3: Decypher
59+
--------------------
60+
61+
The following text contains an encrypted word:
62+
63+
.. code:: python3
64+
65+
name = "CSAIPRALKAINACZEYLVOST"
66+
67+
Print every second character, starting with the 2nds.
68+
69+
70+
Exercise 4: Slicing puzzle
71+
--------------------------
72+
73+
Use the expressions to modify the list as indicated. Use each expression
74+
once.
75+
76+
.. figure:: list_funcs1.png
77+
:alt: list funcs exercise1
78+
79+
list funcs exercise1
80+
81+
82+
Exercise 5: Blocks
83+
------------------
84+
85+
The following code is creating the first two blocks for a `transposition cipher <https://en.wikipedia.org/wiki/Transposition_cipher>`__ .
86+
Complete the code by creating the other two blocks as well.
87+
88+
.. code:: python3
89+
90+
message = "MEETINGATDAWNATTHEBRIDGE"
91+
92+
block1 = message[0::4]
93+
block2 = message[1::4]
94+
___
95+
___
96+
encrypted = block1 + block2 + block3 + block4
97+
98+
99+
Exercise 6: Transposition Cipher
100+
--------------------------------
101+
102+
Complete the program that encrypts a text using a transposition cipher:
103+
104+
.. code:: python3
105+
106+
message = input("enter the text to encrypt: ")
107+
encrypted = ""
108+
for start in range(4):
109+
___
110+
111+
Exercise 7: Decrypt
112+
-------------------
113+
114+
Write a program to decrypt an encrypted message again.
File renamed without changes.
File renamed without changes.

index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ First Steps
3636
first_steps/guess_the_number.rst
3737
first_steps/cypher.rst
3838
first_steps/bill.rst
39-
first_steps/slideshow.rst
4039
first_steps/dictionaries.md
40+
first_steps/indexing.rst
41+
first_steps/slideshow.rst
4142

4243

4344
Tabular Data
@@ -46,7 +47,6 @@ Tabular Data
4647
.. toctree::
4748
:maxdepth: 1
4849

49-
data_structures/indexing.rst
5050
data_structures/tables.md
5151
tabular_data/readfile.md
5252
tabular_data/parsing.md

0 commit comments

Comments
 (0)