Data Types and Variables
Functions and Parameters
Conditionals
Code Challenges
What's Wrong With This Code?
100

What type is True in Python?

Boolean

100

What's a parameter in a function?

A named input variable in the function signature.

100

What does this check?
if x == 5:
    print("Yes")

Checks if x equals 5

100

Write a loop that prints every letter in "code".

for c in "code":
    print(c)

100

if name = "Alex":
    print("Hi")

Use == not = in the if

200

What does str(5) return?

"5"

200

True or False: All functions need at LEAST one parameter to compile.

False. Ex: greet()

200

What is the difference between = and ==?

= assigns; == compares

200

Write a function that returns a boolean for whether a number is even using modulo.

def is_even(n):

    return n % 2 == 0

200

name == input('Name?')
print("Hi" + name)

name = input("Name?")
print("Hi", name)

==, +, '   '

300

What's the difference between a list and a string?

A list can be changed and holds items; a string is text that cannot be changed.

300

Write a function that takes a name and prints
"Hi, [name]!"

def welcome(name):
    print(f"Hi, {name}!")

300

What statement would you use to chain multiple checks?

"elif"

300

Write code that prints only the even numbers from 1–10

for i in range(1, 11):
    if i % 2 == 0:
        print(i)

300

def greet:
    print("Hello")

Need parentheses: def greet():

400

What will type(3.0+4) return?

<class 'float'>

400

What does this print?
def square(n):
   for i in range(4):
       n *= 2
   return n
print(square(5))

80

400

Write an if/else block that prints “Even” or “Odd” based on a number.

if n % 2 == 0:
    print("Even")
else:
    print("Odd")

400

Write code that takes this list:
fruits = ["apple", "banana", "cherry"]
…and adds "orange" after "banana" using a list function.

fruits.insert(2, "orange")
print(fruits)

400

x = input("Enter a number: ")
print(x * 2)

input() returns str, so "3"*2 yields "33"—need int(x)

500

What will return from these lines of code?
datatype = ("abc", 34, True, 40, "male")
type(datatype)

<class 'tuple'>

500

Write a recursive function factorial(n) that returns the factorial of n.

def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n - 1)

500

What does this print if x = 4 and y = 10?
if x > 3 and y < 10:
    print("A")
elif x == 4 or y == 4:
    print("B")
elif not x == 4:
    print("C")
else:
    print("D")

B

500

Write code to check if a user-entered password has at least 8 characters and includes the digit 1.

pwd = input("Pass:")
if len(pwd) >= 8 and "1" in pwd:
    print("OK")
else:
    print("Not OK")

500

nums = (1, 2, 3, 4, 5)
for n in nums:
    if n % 2 == 0:
        nums.remove(n)
print(nums)

nums is a tuple and CANNOT be changed.
nums = [1, 2, 3, 4, 5] is a list.