ValueError: invalid literal for int() with base 10: 'abc'
ValueError: too many values to unpack
ValueError: list.remove(x): x not in list
A function received an argument of the correct type but an inappropriate value.
Fix 1: Invalid Conversion
# β Converting non-numeric string to int
num = int("abc") # π₯
# β
Validate first
user_input = "abc"
if user_input.isdigit():
num = int(user_input)
else:
print("Not a number")
# β
Or use try/except
try:
num = int(user_input)
except ValueError:
num = 0 # Default
Fix 2: Too Many / Too Few Values to Unpack
# β Wrong number of variables
a, b = [1, 2, 3] # π₯ Too many values
a, b, c = [1, 2] # π₯ Not enough values
# β
Match the count
a, b, c = [1, 2, 3]
# β
Or use * to capture extras
a, *rest = [1, 2, 3] # a=1, rest=[2, 3]
Fix 3: Item Not in List
# β Removing item that doesn't exist
items = [1, 2, 3]
items.remove(5) # π₯
# β
Check first
if 5 in items:
items.remove(5)
Fix 4: Invalid Date/Time
# β Invalid date
from datetime import date
d = date(2026, 13, 1) # π₯ Month 13
# β
Validate input
month = 13
if 1 <= month <= 12:
d = date(2026, month, 1)
Fix 5: math.sqrt of Negative Number
# β Square root of negative
import math
math.sqrt(-1) # π₯
# β
Check or use cmath
if x >= 0:
result = math.sqrt(x)
# For complex numbers
import cmath
result = cmath.sqrt(-1) # 1j