## Deques of Python Stories

I was introducing deques in my Computer Science 1 class today in Python and decided to tell a story around the lesson. I figured I would share as this seemed to sink-in with my classes.

Zara loves Computer Science and using technology. She is hosting a party with several of her friends and wants to have their names displayed on the screen in the order they arrived and then remove them when they depart.

The friends of Zara are:

• Alice
• Betty
• Christy
• Darla
• Elizabeth
• Fran
• Ginger
• Holly

Alice, Betty and Christy arrive at the party at the same time and enter in that order.

```from collections import deque
myGuestList = deque(["Alice", "Betty", "Christy"])
print(myGuestList)```

At this point, we have 3 guests at the party: Alice in index 0, Betty in index 1, and Christy in index 2.

Darla and Elizabeth arrive at the party at the same time and enter in that order.

```myGuestList.append("Darla")
myGuestList.append("Elizabeth")
print(myGuestList)```

We now have 5 guests at the party: Alice in index 0, Betty in index 1, Christy in index 2, Darla in index 3, and Elizabeth in index 4.

Alice and Betty H-A-T-E Elizabeth. Almost instantly upon seeing her name on the screen, they both leave the party.

```myGuestList.popleft()
myGuestList.popleft()
print(myGuestList)```

We now have 3 guests at the party: Christy has now moved to index 0, Darla has moved to index 1, and Elizabeth has moved to index 2.

Ginger and Holly arrive at the party at the same time and enter in that order.

```myGuestList.append("Ginger")
myGuestList.append("Holly")
print(myGuestList)```

We now have 5 guests at the party: Christy is in index 0, Darla is in index 1, Elizabeth is in index 2, Ginger is in index 3, and Holly is in index 4.

Regretfully, Holly had been to another party before coming to Zara’s party and gets sick when she gets inside and has to leave.

```myGuestList.pop()
print(myGuestList)```

We now have 4 guests at the party: Christy is in index 0, Darla is in index 1, Elizabeth is in index 2, and Ginger is in index 3.

Elizabeth is Holly’s sister and leaves to take care of her sister and possibly ridicule her for her choice of the day.

```del myGuestList[2]
print(myGuestList)```

We now have 3 guests at the party: Christy is in index 0, Darla is in index 1, and Ginger who has moved to index 2.

Zara realizes that while the computer shows 3 guests at the party, there are 4 guests there. Somehow, Fran came in right after Elizabeth and did not get entered into the computer during the “drama” between Alice and Betty with Elizabeth. Fran needs to be entered into the correct location.

```myGuestList.insert(2,"Fran")
print(myGuestList)```

We now have 4 guests at the party: Christy is in index 0, Darla is in index 1, Fran in index 2, and Ginger who has moved to index 3.

Zara realizes that there is one person who has been there the entire time, but is not on the list – herself. Since she has been there the entire time, she should be placed at the bottom of the deque.

```myGuestList.appendleft("Zara")
print(myGuestList)```

We now have 5 people at the party: Zara is in index 0, Christy moves index 1, Darla moves to index 2, Fran moves to index 3, and Ginger moves to index 4.

Everyone, including Zara agrees that the party is pretty lame and that there is a better party down the street. So, everyone is going to leave the party.

```myGuestList.clear()
print(myGuestList)```

We now have nobody at the party and the deque is empty!

## Draft Information Flier for Girls Robotics Summer Camps

Well, it’s looking like it’s going to be more and more of a reality. As we approach the end of February and wrap-up a successful week of touring at Ferris Intermediate with the FTC 11242 robot, it’s time to get an information flier ready for our girls robotics summer camps.

Still have a few logistical issues to iron-down and these fliers will be ready for prime-time. Hopefully, they’ll be ready to go out this time next week.

## Number Conversions from Base 10

I have written a few posts (Post 1, Post 2, & Post 3) concerning various base number systems. In all of these posts, I covered how to convert from a non-decimal base into a decimal base. In other words, I covered how to get INTO base-10. This post is going to cover the inverse (decimal base into non-decimal base).

#### Modulus

We will need to start by reviewing the concept of modulus division. Let’s look at the standard division problem 5/2. We would typically say that the answer is 2.5 and this would be correct.

Now, modulus is simply the remainder of a division problem. Go back to when you were first introduced to division. In Texas, this is typically in 4th grade. Let’s take a look at that division problem of 5/2 again. When you were learning division, you would have said the answer was 2r1. The 1 is the modulus. When we’re writing the problem to just solve modulus, we would write it as 5%2.

#### Mechanics

##### Decimal to Octal

Let’s say that we have the decimal number (base 10) 4,814 and we want to convert it to an octal (base 8).

We will be building the number from right-to-left. The first thing we will do is solve 4,814/8. This equals 601r6. So, our first digit of the solution (starting on the right) is 6.

`6`

Now, we solve 601/8, which equals 75r1. So, our second digit of the solution (floating from right-to-left) is 1.

`16`

Now, we solve 75/8, which equals 9r3. So, our third digit of the solution (floating from right-to-left) is 3.

`316`

Now, we solve 9/8, which equals 1r1. So, out fourth digit of the solution (floating from right-to-left) is 1.

`1316`

Finally, we solve 1/8, which equals 0r1. So, our fifth and final digit of the solution (floating from right-to-left) is 1.

`11316`

So, the decimal number (base 10) 4,814 is equal to the octal (base 8) 11316.

As you can see, this is a bit of a process, but once you know the process, it is very simple. I now want to take a look at going to number systems with more digits than base 10, for example: base 16.

Let’s say that we have the decimal number (base 10) 4,814 and we want to convert it to a HEX (base 16).

We start by solving 4,814/16, which gives us 300r14. Remember, that is number systems with more than 10 digits, we start using letters.

10 = A
11 = B
12 = C
13 = D
14 = E
15 = F

So, the first digit of our solution (building from right-to-left) is E.

`E`

Now, we solve 300/16, which gives us 18r12. So, the second digit of our solutions (building from right-to-left) is C.

`CE`

Now, we solve 18/16, which gives us 1r2. So, the third digit of our solution (building from right-to-left) is 2.

`2CE`

Finally, we solve 1/16, which gives us 0r1. So, the fourth digit of our solution (building from right-to-left) is 1.

`12CE`

So, the decimal number (base 10) 4,814 is equal to the hexadecimal (base 16) 12CE.