Creating a Cinema Simulator Using Python

A real-life, beginner-friendly Python program to have fun with

Aryaman Kukal
The Academically Driven
5 min readJun 16, 2020

--

visual credit

This is a perfect example of the combination of logic and loops in Python to create an incredibly powerful program. I will go through everything step by step so you can experience the beauty of this program with me. If you’re new to Python, this is a perfect program to open the door for you. It is meant for absolute beginners.

What is the program about? This program asks a user what movie they want to watch, and decides if they are ready to enjoy the movie by its availability, the user’s age, and the number of tickets left.

Definitions of any Python vocabulary will be listed at the bottom.

I will explain line by line.

1 — I created a variable called films which is basically a dictionary.

2 to 6 — I created a dictionary with 4 pairs of keys and values. Each key is a string set as the name of some movie. Since each value is a list of 2 values, the first one for each is the age requirement, and the second is the number of tickets left for the specific movie.

7 — I created a while loop with the condition True, which is one of the boolean, and since True is always True, it will make the entire program run forever.

8 — I created another variable called choice that should store the user input statement asking what movie the user would like to watch.

9 — I added 2 string methods at the end of the statement because the type of the input should be a string. The .strip() takes away any extra spaces from the input, and the .title() makes the first letter of each word in the input uppercase. Since strings are iterable, we can perform these tasks.

Note: When writing if statements, we first always assume that the condition will have a result of True, so we can keep the code going. The code that’s supposed to run when the condition is False is usually written after.

10 — I created an if statement stating: if choice in films, which basically translates to: if the movie that the user gave as input is inside the films dictionary as a key…

11 Inside the if statement, I created a variable called age, that should store the user input statement asking how old the user is. Notice how I added an int before the statement. This stands for integer, and since the age has to be given as an integer, you have to add this.

12I created another if statement stating that, if the age the user gave as input is greater than or equal to films[choice][0]… films[choice][0] translates to: go to the films dictionary, go to the film the user choose (the key), and then go to the 0th index of the values of that certain key, which is the 1st value in the list of values. The index represents the age requirement for that movie.

13 If the above line is True, I created another if statement stating, if films[choice][1] is greater than 0…The index is now 1, so it’ referring to the 2nd value in the list of values for that certain key. The second value represents the number of tickets left for that movie. The line means: if the number of tickets for that movie has not run out…

14 If the above is True, print, or display “Enjoy the film!” to the screen.

15 We already know that films[choice][1] is the number of tickets left for that movie. This line is reassigning a value to this original value. films[choice][1] = films[choice][1]-1 translates to, take away 1 ticket from the number of tickets and put that value back into films[choice][1].

16 to 17 In this line, we want to print, or display how many tickets are left for that specific movie. We already know that value as films[choice][1], so we just need to add that in between the print statement, and the computer will return its value automatically, along with the other string parts.

18 to 19I created an else statement that will run if the condition for its corresponding if statement is False. It will display to the screen, “Sorry, we are all sold out!”

20 to 21The else statement will display to the screen, “You are too young to see that film!”

22 to 23The else statement will display to the screen, “We don’t have that film…”

Note: Notice how the else statements perfectly align with the if statements in a column form. This is a way you can tell which else statement refers to which if statement. You can see this in the following: the entire program.

And we’re done. Try running the program for yourself.

Feel free to add as many movies as you desire.

PROGRAM FORMATTING MIGHT NOT BE 100% ACCURATE!

Important Vocabulary:

For the beginners reading this: good luck in your Python programming journey! It will be a great one!

Write your mind, or read other’s. Visit The Academically Driven!

Email: theacademicallydriven@gmail.com

Instagram: @theacademicallydriven

Facebook: @theacademicallydriven

LinkedIn: The Academically Driven

Twitter: @AcademicallyThe

--

--

Aryaman Kukal
The Academically Driven

tech enthusiast ~ programmer ~ avid writer ~ always curious; rarely express it ~ freshman @ American High ~ “Make it work, make it right, make it fast.”