Python Fundamentals Review

Master the basics with interactive challenges

⏱️ ~60 minutes • 36 questions
// overall_progress 0 / 36 completed
📥

Input & Output

Learn to communicate with your programs

Multiple Choice
What function is used to display output to the screen in Python?
echo()
print()
display()
output()
Fill in the Blank
Complete the code to ask the user for their name and store it:
name = ("What is your name? ")
Code Challenge
Write code that prints "Hello, World!" to the screen:
Multiple Choice
What will this code print?
print("Hello", "World")
HelloWorld
Hello World
Hello, World
Error
Debug This Code
This code should ask for a name and greet the user, but it has a bug. What's wrong?
name = input("Enter your name: ") print("Hello, " + Name)
Variable name is wrong case (Name vs name)
Missing quotes around Hello
Should use comma instead of +
input() is used incorrectly

Hint: Python is case-sensitive!

📦

Variables

Store and manage data in your programs

Multiple Choice
Which of the following is a valid variable name in Python?
2nd_place
my-variable
user_age
class
Fill in the Blank
Complete the code to convert the string "42" to an integer:
text = "42" number = (text)
Multiple Choice
What will be the value of result after this code runs?
x = 5 y = 3 result = x + y * 2
16
11
13
10
Code Challenge
Create a variable called age and assign it the value 15:
Multiple Choice
What is the data type of the variable x?
x = "100"
int (integer)
str (string)
float
bool (boolean)
Debug This Code
This code should calculate the total price, but it has a bug. What's wrong?
price = input("Enter price: ") quantity = input("Enter quantity: ") total = price * quantity print("Total:", total)
Need to convert inputs to int() or float()
Should use + instead of *
Variables need quotes around them
There is no bug

Hint: What data type does input() return?

🔀

If Statements

Make decisions in your code

Multiple Choice
What will this code print?
x = 10 if x > 5: print("big") else: print("small")
big
small
Error
Nothing
Fill in the Blank
Complete the code to check if a number is negative:
num = -5 if num 0: print("Negative!")
Multiple Choice
Which keyword is used for "otherwise if" in Python?
else if
elseif
elif
otherwise
Code Challenge
Write an if statement that prints "Pass" if the variable score is greater than or equal to 60:
Multiple Choice
What will this code print?
age = 15 if age >= 18: print("Adult") elif age >= 13: print("Teen") else: print("Child")
Adult
Teen
Child
Adult, Teen, and Child
Debug This Code
This code should check if a number is even, but it has a bug. What's wrong?
num = 4 if num % 2 = 0: print("Even")
Should use == instead of = for comparison
% is not a valid operator
Missing colon at the end
Wrong indentation

Hint: = assigns a value, but what compares values?

🔄

While Loops

Repeat actions until a condition is met

Multiple Choice
How many times will "Hello" be printed?
count = 0 while count < 3: print("Hello") count = count + 1
2 times
3 times
4 times
Infinite loop
Fill in the Blank
Complete the code to create a loop that runs while x is not equal to 10:
x = 0 while x 10: x = x + 1
Multiple Choice
What keyword immediately exits a while loop?
exit
stop
break
end
Code Challenge
Write a while loop that prints numbers from 1 to 5:
Multiple Choice
What will be the value of x after this loop finishes?
x = 1 while x < 10: x = x * 2
8
10
16
32
Debug This Code
This code should print numbers 1 to 5, but it runs forever. What's the bug?
num = 1 while num <= 5: print(num)
Missing num = num + 1 to increment the counter
Should use < instead of <=
num should start at 0
Missing break statement

Hint: If the condition never becomes False, what happens?

Functions

Create reusable blocks of code

Multiple Choice
Which keyword is used to define a function in Python?
function
def
func
define
Fill in the Blank
Complete the function to return the sum of two numbers:
def add(a, b): a + b
Multiple Choice
What will this code print?
def greet(name): print("Hi " + name) greet("Alice")
Hi name
Hi Alice
greet Alice
Error
Code Challenge
Write a function called double that takes a number and returns it multiplied by 2:
Multiple Choice
What will result be after this code runs?
def multiply(x, y): return x * y result = multiply(4, 5)
9
20
45
None
Debug This Code
This function should return the square of a number, but it doesn't work correctly. What's the bug?
def square(n): n * n result = square(5) print(result) # Prints None!
Missing return keyword before n * n
Should use ** instead of *
Function is called incorrectly
Variable name 'n' is invalid

Hint: How do you send a value back from a function?

🎯 Final Project Review

Combine everything you've learned!

Fill in the Blank
Complete this number guessing game - fill in the missing parts:
secret = 7 guess = 0 while guess secret: guess = (input("Guess: ")) if guess < secret: print("Too low!") elif guess > secret: print("Too high!") print("You got it!")
Multiple Choice
What does this program do?
def check(n): if n > 0: return "positive" elif n < 0: return "negative" else: return "zero" num = int(input("Number: ")) print(check(num))
Checks if a number is positive, negative, or zero
Adds numbers together
Counts from 1 to the number
Prints "positive" always
Code Challenge
Write a complete program that:
1. Asks the user for their name using input()
2. Creates a function called welcome that takes a name and prints "Welcome, [name]!"
3. Calls the function with the user's name
Code Challenge
Write a function called countdown that takes a number and uses a while loop to print numbers from that number down to 1, then prints "Blast off!":
Debug This Code
This password checker should keep asking until the correct password is entered, but it has a bug. Find the main issue:
def check_password(pw): if pw = "secret123": return True else: return False correct = False while correct == False: password = input("Password: ") correct = check_password(password)
Uses = instead of == in the if statement
While condition is wrong
Return statements are wrong
Function is called incorrectly

Hint: Remember the difference between = and ==

Multiple Choice
What will this program print when the user enters 3?
def sum_to_n(n): total = 0 count = 1 while count <= n: total = total + count count = count + 1 return total num = int(input("Enter number: ")) print(sum_to_n(num))
3
6
9
0
Code Challenge
Write a complete program that:
1. Creates a function called is_even that takes a number and returns True if it's even, False if odd
2. Uses a while loop to ask the user for numbers
3. For each number, prints whether it's even or odd
4. Stops when the user enters 0