Control Flow
Variable Type
Print, Input, Randomness
Python and Programming Facts
100

What will be printed?

like_sunny_day = True;

like_rainy_day = True;

if(like_sunny_day):

    print("raise hand.")

if(like_rainy_day):

    print("stand up.")

raise hand.

stand up.

100

What are the four types of values (data types) we’ve used to store information in variables?

string, integer(int), float, boolean(bool)

100

What will this print?

print("The answer is", 3 + 4)

The answer is 7

100

What is a bug?


  • A bug is a mistake in the code that causes the program to work in the wrong way. It can make a game crash, a robot move the wrong direction, or a website act weird.

  • Think of the missing indents that we've encountered in this class! 

  • Why is it called a “bug”?

    • Long ago, in 1947, a real moth got stuck inside a big computer and caused it to break. A scientist found it and taped it into her notebook with the words:

      “First actual case of bug being found.” 🐛

      Since then, people started calling all software mistakes “bugs” — even if they’re just typing mistakes!


200

What will be printed?

is_batman = False

trusted_by_batman = True

can_enter_batcave = False

if(is_batman or trusted_by_batman):

    can_enter_batcave = True

if(can_enter_batcave):

    print("Welcome!")

else:

    print("Alarm activated!)

Welcome!

200

What is the type of mystery?

mystery = "42"

string

200

What does this code print?

name = input("What's your name? ")

print("Hello " + name + "!")

It prints “Hello” followed by whatever the user typed!

200

What is indentation used for in Python?

To show which lines of code belong together — like inside an if or a loop.  

300

What will be printed and why?

wizard = "Hermione"

wand = "broken"

knows_spell = True


if (wizard == "Harry" or wizard == "Hermione") and knows_spell and wand != "broken":

    print("Spell succeeds!")

else:

    print("Spell fails!")

Spell fails

🧠 Why?

Even though the wizard is Hermione and she knows the spell, her wand is broken, so the whole and condition fails.

300

What's the variable type of banana?


banana = (1.5*3 == 4.5)?

boolean

300

What does this code print?

name = input("What’s your name?")

print("Hello, name!")

Hello, name!

300

Programming languages have been around for decades, but approximately how many different programming languages exist in the world today? How many programming languages are there in the world?

There are over 700 programming languages, but only a few dozen are commonly used.


400

Do these two pieces of code do the SAME thing? Why or why not?

1.

if time > 22:

    if is_alone or with_dumbledore:

        print("Harry enters the Room of Requirement.")

    else:

        print("Door stays shut.")

else:

    print("Door stays shut.")

2. 

if (time > 22 and is_alone) or with_dumbledore:

    print("Harry enters the Room of Requirement.")

else:

    print("Door stays shut.")

No!

Code 1 only lets Harry in after 10 PM (time > 22), even if he's with Dumbledore.

Code 2 lets Harry in any time if he's with Dumbledore.

400

What is the final type of magic?

magic = 9

magic = "Alohomora!"


string

400

Will this ever print “You win!”? Why or why not?

import random

guess = 5

number = random.randint(6, 10)

if guess == number:

    print("You win!")

No, because 5 can never equal a number from 6 to 10!

400

When was the Python programming language first created?

Python was created by Guido van Rossum and released in 1991.

500

Do these two pieces of code do the same thing? Why or why not?

1️⃣

if magic_level > 7:

    if knows_patronus:

        print("Dementors run away!")

    else:

        print("Harry panics!")

else:

    print("Harry hides!")

2️⃣

if magic_level > 7 and knows_patronus:

    print("Dementors run away!")

else:

    if magic_level > 7:

        print("Harry panics!")

    else:

        print("Harry hides!")

Yes, they do the same thing!

🧠 Why?

Both versions:

  • First check if magic_level > 7

  • Then, if that’s true, they check knows_patronus

  • If not true, they go to “Harry hides!”

500

What's the final type of potion?

potion = 10

potion = potion + 3.5


float

500

What’s one thing that could go wrong here?

age = input("How old are you? ")

print(age + 1)

It gives an error because age is a string, not a number!

500

What is Python named after?

It’s named after Monty Python, a British comedy group — not the snake! 

Guido van Rossum, the creator of Python, was a fan of Monty Python's Flying Circus and wanted a short, unique, and slightly mysterious name for the language.