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.
What are the four types of values (data types) weâve used to store information in variables?
string, integer(int), float, boolean(bool)
What will this print?
print("The answer is", 3 + 4)
The answer is 7
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!
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!
What is the type of mystery?
mystery = "42"
string
What does this code print?
name = input("What's your name? ")
print("Hello " + name + "!")
It prints âHelloâ followed by whatever the user typed!
What is indentation used for in Python?
To show which lines of code belong together â like inside an if or a loop.
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.
What's the variable type of banana?
banana = (1.5*3 == 4.5)?
boolean
What does this code print?
name = input("Whatâs your name?")
print("Hello, name!")
Hello, name!
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.
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.
What is the final type of magic?
magic = 9
magic = "Alohomora!"
string
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!
When was the Python programming language first created?
Python was created by Guido van Rossum and released in 1991.
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!â
What's the final type of potion?
potion = 10
potion = potion + 3.5
float
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!
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.