Python Paper
Python Paper
You're tracking inventory for a small store. You have a dictionary, stock, where keys are
product names and values are quantities:
Question 1: An event registration system uses the variables is_member, paid_early, and
has_guest. Write functions for these situations:
• Base cost: $5
• IF weight > 10 lbs, add $5 per pound over 10
• IF distance > 500 miles, add $7
• IF is_priority is True, double the total cost.
• Task: Test with target at the start, in the middle, multiple times, and NOT in the
list.
Question 7: filter_positives(numbers):
• Return a new list with only the positive values from numbers.
• Task: Test cases with all positives, all negatives, a mix, and an empty list.
Question 8: find_duplicates(items):
• Return a list with only the elements that appear more than once in items.
• Task: Tests with multiple repeated items, items repeating only twice, and no
duplicates.
Question 9: is_special(num):
• Return True if a number is EITHER divisible by 4 OR ends in the digit 2; but NOT
both.