Skip to content
Chapter Practice Arena

Variables and Basic Data Problems

Targeted practice challenges specifically curated for this chapter. Inspect hints, verify outputs, and check Pythonic solutions.

All Chapters
Difficulty:
Chapter:
Showing 6 challenges · 30 total · Page 1 of 5
#1intermediateOperators in Python
Create two separate lists, a = [1, 2] and b = [1, 2]. Print their equality comparison and identity comparison.
Starter Code
a = [1, 2]
b = [1, 2]
# Print equality and identity checks
Expected Output:True False
#2intermediateType Conversion
Write a program that attempts to convert the string "hello" to an integer. If conversion fails, print "Invalid integer".
Starter Code
text = "hello"
# Attempt the conversion and handle the expected error
Expected Output:Invalid integer
#3beginnerData Types in Python
Create variables count = 7, ratio = 2.5, label = "ready", and active = True. Print the type of each value on its own line.
Starter Code
count = 7
ratio = 2.5
label = "ready"
active = True

# Print each value type
Expected Output:<class 'int'> <class 'float'> <class 'str'> <class 'bool'>
#4beginnerData Types in Python
Without running the code, predict the output. Then run it and explain why int(6.8) produces the displayed result.
Starter Code
value = 6.8
print(int(value))
print(type(value))
Expected Output:6 <class 'float'>
#5intermediateOperators in Python
Given profile = {"name": "Asha", "active": True}, print whether "name" is a key and whether "Asha" is a value.
Starter Code
profile = {"name": "Asha", "active": True}
# Check the key and the value
Expected Output:True True
#6beginnerVariables in Python
Given a = 5 and b = 8, swap their values using Python multiple assignment. Print both values on one line separated by a space.
Starter Code
a = 5
b = 8
# Swap values
# Print a and b
Expected Output:8 5
…