Chapter Practice Arena
All ChaptersVariables and Basic Data Problems
Targeted practice challenges specifically curated for this chapter. Inspect hints, verify outputs, and check Pythonic solutions.
Difficulty:
Chapter:
Showing 6 challenges · 30 total · Page 1 of 5
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
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
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'>
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'>
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 valueExpected Output:True
True
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
…