This type of variable represents whole numbers (e.g., 1, 2, 3..)
Integer
What is wrong with the following if statement
if x = 5:
print("x is a 5")
It should use == instead of =
What is the output of
x = 2
y = 3
z = x*y
print(z)
6
What is the output of the following program? Assume the user enters “Florence” then “Fernandez”.
first_name = input("What is your first name? ") last_name = input("What is your last name? ") whole_name = first_name + last_name print(whole_name)
FlorenceFernandez
Bonus: How do you fix it?
What will this code print?
x = 2.2
print(int(x))
2
This type of variable represents only two values (i.e., TRUE or FALSE)
Boolean
This code should combine "Hello" and "World", but it gives a TypeError:
greeting = "Hello" + 5
What is wrong with this code?
It is attempting to concatenate a string ("Hello") and an integer (5)
What is this operator?
!=
Not equal to
This is used in conjunction with IF statements (and ELIF statements) to provide an alternative block of code to execute when the IF conditions are not met
What is ELSE
What is the output of this pseudo-code
if(this review is awsome):
Result = I'm going to do great on the test
else:
Result = I'm cooked
I'm going to do great on the test
This type of variable stores a sequence of characters (e.g. "The quick brown fox jumps over...")
String
Suppose you want to repeat the string "cat" four times. What is wrong with the following
print(4*"cat")
Python cannot multiply a string by number.
What is the output?
x=5
y=6
z = (x<y)
print(z)
True
This is used when a first condition is false and you want to test another condition
What is ELIF
What will this code do?
name = "Alice"
print("Hello " + name + "!")
It will print:
Hello Alice!
This type of variable represents a number with a decimal part (e.g. 3.1415).
Float
What is wrong with the following?
x=int(4)
y=int(3.2)
z=x*y
print (z)
The number 3.2 is not an integer. It should be a floating-point number (float)
What is the output of
x = 2**3
print(x)
8
What will this code output
num1 = input("Enter a number: ")
num2 = input("Enter another number: ")
sum = num1 + num2
print("Sum:", sum)
12
Bonus: How can you fix the code to display the correct sum?
Why will this code cause an error?
x = 10
if x > 5:
print("x is big")
The print statement must be indented
This type of variable stores a collection of items as a single variable (e.g., ages =[16, 26, 29])
List
Which line will cause an error
1. weight = input("How much do you weigh? ")
2. oz_water = weight / 2
3. print("You should drink " + str(oz_water))
4. print("ounces of water every day if you weigh " + weight)
Line 2 because the input will be a string, and Python cannot divide a string by 2
What is the output
x = 5
x = x + 5
print(x)
10
What will be the output of this program?
number = 5
greater_than_zero = number > 0
if greater_than_zero:
print(number)
5
What is the output of
x = round(0.0379,3)
print(x)
0.038