Python Magic Trick: Guess My Number

Guess My Number: a Simple Magic Trick Elevated through a Python Script

Codecademy’s CS101 Final Project

Why Program a Magic Trick?

My grandpa was a successful astronomer and a huge math buff. He shared this ‘magic trick’ with my brother and me when we were children. We immediately loved it because it was easy to understand and fun to perform on our own. I decided to program this trick as part of my CS101 final project of the Codecademy Career Path for the exact same reason. As I started to code, I quickly realized that Python would allow me to make the trick even more interesting because the player can pick their own numbers for the calculation, leading to a different end result every time, thus adding to the ‘magic’ :).

The Code

To move through the trick, the player advances by either pressing enter or entering a number. After a welcome message and instructions to choose a number between 1 and 20, the player is prompted to add or subtract with a number of their choice. After four calculations, they are prompted to subtract the original number they picked at the beginning from the number they obtained from the past four calculations.

In the background, the program performed the same calculations starting from the number 0. After the player subtracts their original number, they arrive at the same end result as the background calculations that departed from 0.

In the end, the player is asked if the guess was correct. A ‘yes’ is followed by an evil ASCII art alien whereas a ‘no’ returns a message that asks the player to try again and use a calculator.

Here is the link to my code’s GitHub repository: GitHub - Eumi1408/CS_101_Final_Project: Codecademy's CS Career Path Final Project

I know this script may look like a pathetic attempt to experienced developers, but I am very excited that I programmed something coherent that works! I am looking forward to learning more in Codecademy’s Computer Science Career Path.