What do we use loops for?
To repeat an indented block of code
What is wrong with this syntax? (pretend it is properly indented)
If x<4:
print(x)
"If" should not be capitalized
Is my-variable a valid variable name?
No
What does % do?
it finds the remainder of two numbers
What does the following code print? (pretend it is properly indented)
for x in range(10)
print(x + 1)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
What is wrong with this code? (pretend it is properly indented)
i = 0
while i < 5
print("yes")
i += 1
it is missing a : after i < 5
What do if statements do?
It runs a block of code if a condition is true.
Is _myvar a valid variable name?
Yes
What does != do?
What does writing "break" in your code do?
it exits the loop
What does elif do?
It runs an indented block of code if all previous statements were false and and a condition is true.
What type of variable is input?
string
What is the difference between = and ==?
= assigns a value to a variable
== checks if two values are equal
How do we write code to print "hello" 1000 times?
(pretend this is correctly indented)
i = 0
while i < 1000:
print("hello")
i += 1
What does the "or" keyword check for?
It combines two conditions, and will run the indented code if either condition is true.
How do you change input into an integer?
num = int(input())
What does *= do?
it multiplies a variable by another number and stores the result in the variable.
Write a program that finds the product of all the numbers from 1 to an inputted number N (this is called factorial, and you can write this as N!).
pretend this is correctly indented
n = int(input("enter a number: ")
i = 1
product = 1
while i <= n:
product *= i
i += 1
Will this code print anything? pretend it is indented correctly
if 5>2 and (4<3 or 4>3):
print("yay")
Yes, it will print "yay"
What happens when I run this code?
x = bool("0")
print(x)
it prints True.
What is the difference between / and //?
// does integer division
/ does float division