Complete Python Practice Questions with
Step-by-Step Explanations
LEVEL 1
Q1:
name = "Alex"
print(name)
Output: Alex
Explanation: The variable stores "Alex" and print displays it.
Q2:
1name = "John"
Explanation: Invalid variable name. Variables cannot start with numbers.
------------------------------------------------------------
LEVEL 3
x=5
y = "5"
print(x + int(y))
Step 1: int("5") = 5
Step 2: 5 + 5 = 10
Output: 10
num = input()
print(num + 5)
Explanation: input() returns string. "5" + 5 causes TypeError.
a = 10
b=3
print(a / b) -> 3.3333333333333335
print(a // b) -> 3
Explanation:
/ gives decimal division.
// gives floor division.
------------------------------------------------------------
LEVEL 4
x = "10"
y=5
print(int(x) + y * 2)
Step 1: int("10") = 10
Step 2: 5 * 2 = 10
Step 3: 10 + 10 = 20
Output: 20
name = "Sam"
age = 16
print("My name is " + name + " and I am " + age)
Explanation: Error because age is integer.
Correct: convert age using str() or use f-string.
a=5
b=2
print(a + b * 3)
Step 1: 2 * 3 = 6
Step 2: 5 + 6 = 11
Output: 11
------------------------------------------------------------
LEVEL 5
x = input()
y = int(x) + 3
print(x * 2)
print(y)
If input is 5:
"5" * 2 = "55"
5+3=8
Output:
55
8
------------------------------------------------------------
LEVEL 6
x = "6"
y=2
print(x * y + str(y))
"6" * 2 = "66"
str(2) = "2"
"66" + "2" = "662"
Output: 662
------------------------------------------------------------
LEVEL 7
x = "3"
y=4
z=2
print(int(x) + y * z)
print(x + str(y) * z)
First:
int("3") = 3
4*2=8
3 + 8 = 11
Second:
str(4) = "4"
"4" * 2 = "44"
"3" + "44" = "344"
Outputs:
11
344
------------------------------------------------------------
LEVEL 8
x=2
y = "5"
print(x * int(y) + int(y))
print(str(x) * int(y))
First:
2 * 5 = 10
10 + 5 = 15
Second:
"2" * 5 = "22222"
Outputs:
15
22222
------------------------------------------------------------
LEVEL 9
x = "12"
y=3
print(int(x) * y + len(x))
int("12") = 12
12 * 3 = 36
len("12") = 2
36 + 2 = 38
Output: 38
a = "7"
b=2
c=3
print(a * b + str(c))
"7" * 2 = "77"
str(3) = "3"
"77" + "3" = "773"
Output: 773
num = "4"
print(num * int(num))
"4" * 4 = "4444"
Output: 4444
------------------------------------------------------------
LEVEL 10
x = "5"
y=2
x = int(x) + y
print(str(x) * y)
int("5") = 5
5+2=7
"7" * 2 = "77"
Output: 77
------------------------------------------------------------
LEVEL 11
x = "2"
y=3
z=1
print(int(x) + y * z) -> 5
print((int(x) + y) * z) -> 5
print(x * (y - z)) -> "22"
------------------------------------------------------------
LEVEL 12
a = "10"
b=2
print(int(a) // b) -> 5
print(a // str(b)) -> TypeError
Explanation:
Strings do not support division operators.
------------------------------------------------------------
LEVEL 13
x = "3"
y=3
print(x * y + str(y) * int(x))
"3" * 3 = "333"
"3" * 3 = "333"
"333" + "333" = "333333"
Output: 333333
------------------------------------------------------------
END OF DOCUMENT