PyStart

Practice Exercises

Test your understanding with hands-on exercises. Reveal answers when you're ready.

1 1.1 What is Python

1
Multiple Choice

Which of the following is Python commonly used for?

A. Web development
B. Data analysis and machine learning
C. Automation and scripting
D. All of the above
2
Multiple Choice

Why is Python considered beginner-friendly?

A. It uses curly braces for every block, making structure clear
B. Its syntax reads almost like English and uses indentation for blocks
C. It requires compiling before running
D. It only supports one programming paradigm

1 1.2 First Line of Code

1
Code Fill-in

Complete the code to print "Hello, World!"

______("Hello, World!")
2
Coding Task

Write a program that prints your name on one line and your favorite hobby on the next line.

1 1.3 Comments

1
Multiple Choice

Which symbol is used for a single-line comment in Python?

A. //
B. #
C. /* */
D. --
2
Code Fill-in

Add a multi-line comment to describe the program below.

______
This program calculates
the area of a rectangle
______
length = 10
width = 5
area = length * width
print(area)

1 1.4 Variables

1
Coding Task

Write code to create three variables: name (string), age (integer), and height (float). Then print all three.

2
Multiple Choice

Which of the following is NOT a valid variable name in Python?

A. my_name
B. 2nd_place
C. _private
D. score1

1 1.5 Data Types

1
Multiple Choice

What is the data type of 3.14 in Python?

A. int
B. float
C. str
D. bool
2
Code Fill-in

Create one variable of each type: int, float, str, and bool. Then print each with its type.

1 1.6 Type Conversion

1
Code Fill-in

Fill in the blank to convert the string to an integer:

age_str = "25"
age_int = ______(age_str)
print(age_int + 5)  # Should print 30
2
Coding Task

Write code that adds an integer and a float together, then prints the result and its type.

1 1.7 Input

1
Code Fill-in

Fill in the blank to get the user's favorite color:

color = ______("What is your favorite color? ")
print("You like " + color + "!")
2
Coding Task

Write a program that asks the user for their name and age, then prints a greeting like: "Hello Alice, you are 25 years old!"

1 1.8 Operators

1
Multiple Choice

What does 2 + 3 * 4 evaluate to in Python?

A. 20
B. 14
C. 24
D. 9
2
Code Fill-in

Fill in the blank using the modulo operator to get the remainder of 17 divided by 5:

remainder = 17 ______ 5
print(remainder)  # Should print 2
3
Coding Task

Write a program that asks the user for a number and tells them whether it is even or odd using the % operator.

2 2.1 if Statement

1
Coding Task

Write a program that checks if a number is positive and prints "Positive number!" if it is.

2
Multiple Choice

What is wrong with this Python code?

if x > 10
    print("Big")
A. The print statement should not be indented
B. The condition should use == instead of >
C. Missing colon (:) after the condition
D. x needs to be in quotes

2 2.2 if…else

1
Coding Task

Write a program that checks if a number is even or odd and prints the result.

2
Code Fill-in

Complete the pass/fail checker. A score of 60 or above is a pass:

score = int(input("Enter your score: "))
______ score >= 60:
    print("Pass!")
______:
    print("Fail!")

2 2.3 if…elif…else

1
Coding Task

Write a grading program: 90+ = A, 80–89 = B, 70–79 = C, 60–69 = D, below 60 = F.

2
Coding Task

Write a season detector: month 3–5 = Spring, 6–8 = Summer, 9–11 = Autumn, 12/1/2 = Winter.

2 2.4 Nested if

1
Coding Task

Write a program that checks if a number is positive, and if so, also checks whether it is even or odd.

2
Coding Task

Write a login checker: first check the username, then (if correct) check the password. Print "Access granted" only if both are correct.

2 2.5 Branching Practice

1
Coding Task

Write a leap year checker. A year is a leap year if: divisible by 4 AND (not divisible by 100 OR divisible by 400).

2
Coding Task

Write a discount calculator: under $50 = no discount, $50–$99 = 10% off, $100–$199 = 20% off, $200+ = 30% off. Print the final price.

3
Coding Task

Write a simple calculator: ask for two numbers and an operator (+, -, *, /), then print the result. Handle division by zero.

3 3.1 for Loop

1
Coding Task

Write a for loop that prints the numbers 1 to 10, each on a new line.

2
Coding Task

Write a for loop that prints each character of the string "Python" on a separate line.

3 3.2 while Loop

1
Coding Task

Write a countdown from 10 to 1 using a while loop. Print "Liftoff!" at the end.

2
Coding Task

Write a program that keeps asking the user for input until they type "quit". Print each input they give.

3 3.3 break / continue

1
Coding Task

Write a loop that prints numbers 1 to 10, but stops (using break) when it finds the number 7.

2
Coding Task

Write a loop that prints numbers 1 to 10, but skips (using continue) the even numbers — only odd numbers should print.

3 3.4 Nested for Loops

1
Coding Task

Print a 5×5 multiplication table using nested for loops.

2
Coding Task

Print a right triangle pattern of stars with 5 rows:

*
**
***
****
*****

3 3.5 Nested while Loops

1
Coding Task

Write a number pyramid pattern using nested while loops:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
2
Coding Task

Write a countdown with an inner countdown: outer loop goes from 3 to 1, inner loop counts from 3 down to the current outer value. Print each number.

3 3.6 Mixed Branch + Loop

1
Coding Task

Find and print all even numbers between 1 and 20 using a loop and an if statement.

2
Coding Task

Write FizzBuzz for numbers 1 to 20: print "Fizz" for multiples of 3, "Buzz" for multiples of 5, "FizzBuzz" for multiples of both, or the number itself.

4 4.1 Built-in Functions

1
Multiple Choice

What does len("Python") return?

A. 5
B. 6
C. 7
D. "Python"
2
Code Fill-in

Fill in the blanks to print the type and value of the variable:

x = 42
______(type(x))   # Should print <class 'int'>
______(x)         # Should print 42

4 4.2 Custom Functions with def

1
Coding Task

Write a function called greet that takes a name as a parameter and prints "Hello, [name]!". Call it with your name.

2
Coding Task

Write a function called separator that prints a line of dashes: "————————————". Call it twice.

4 4.3 Parameters

1
Coding Task

Write a function add that takes two numbers and prints their sum. Call it with 5 and 3.

2
Coding Task

Write a function introduce that takes a name and age, then prints "My name is [name] and I am [age] years old."

4 4.4 Return Values

1
Coding Task

Write a function square that takes a number and returns its square. Print the result of calling square(7).

2
Coding Task

Write a function max_of_two that takes two numbers and returns the larger one. Do not use the built-in max() function.

4 4.5 Nested Function Calls

1
Coding Task

Write two functions: double(n) that returns n*2, and add_ten(n) that returns n+10. Then compose them: print the result of double(add_ten(5)).

2
Coding Task

Write a function circle_area that calculates a circle's area, and another function circle_info that calls circle_area internally and prints "Area: [result]".