Chapter 3
3.1 Even or odd?
# Step 1: Store a number in a variable
number = 7
# Step 2: Check if the number is even or odd using if/else
if number % 2 == 0:
print(number, "is even.")
else:
print(number, "is odd.")
# Bonus Challenge: Use ternary operator
result = "even" if number % 2 == 0 else "odd"
print(number, "is", result + ".")
3.2 Dachshund weight classification
# Step 1: Store the dachshund's name
name = "Wiesje"
# Step 2: Store the weight in kilograms
weight_kg = 2.5
# Step 3: Convert weight to pounds
weight_lbs = weight_kg * 2.2
# Step 4: Classify the dachshund's size
if weight_lbs < 12:
classification = "Kaninchen"
elif 12 <= weight_lbs <= 16:
classification = "Miniature"
else:
classification = "Standard"
# Step 5: Print the result
print("With a weight of", weight_kg, "kgs,", weight_lbs, "lbs, dachshund...