Variable Types
Find the Error
Python Operators
Programming Techniques
Potpourri
100

This type of variable represents whole numbers (e.g., 1, 2, 3..)

Integer

100

What is wrong with the following if statement

if x = 5:

    print("x is a 5")

It should use == instead of =



100

What is the output of

   x = 2

   y = 3

   z = x*y

   print(z)

6

100

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?

100

What will this code print?

 x = 2.2

 print(int(x))


2

200

This type of variable represents only two values (i.e., TRUE or FALSE)

Boolean

200

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)

200

What is this operator?

  !=

Not equal to

200

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

200

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

300

This type of variable stores a sequence of characters (e.g. "The quick brown fox jumps over...")

String

300

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.

300

What is the output?

   x=5

   y=6

   z = (x<y)

   print(z)

True

300

This is used when a first condition is false and you want to test another condition

What is ELIF

300

What will this code do? 

   name = "Alice"

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

It will print:

Hello Alice!  

400

This type of variable represents a number with a decimal part (e.g. 3.1415).

Float

400

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)

400

What is the output of 

   x = 2**3

   print(x)

8

400

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?

400

Why will this code cause an error?

   x = 10

   if x > 5:

   print("x is big")

The print statement must be indented

500

This type of variable stores a collection of items as a single variable (e.g., ages =[16, 26, 29])

List

500

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

500

What is the output

   x = 5

   x = x + 5

   print(x)

10

500

What will be the output of this program?

   number = 5 

   greater_than_zero = number > 0

   if greater_than_zero:    

        print(number)

5

500

What is the output of 

   x = round(0.0379,3)

   print(x)

0.038

M
e
n
u