Function receives an argument with the right type but inappropriate value.
A ValueError is raised when a built-in operation or function receives an argument that has the right type but an inappropriate value. For example, passing a non-numeric string to `int()` raises a ValueError because while the argument is a string (correct type for `int()`), its content cannot be parsed as an integer.
This typically occurs when: converting incompatible strings to numbers, unpacking a sequence with the wrong number of values, passing out-of-range values to math functions (like `math.sqrt(-1)` for real numbers), or supplying invalid format strings.
1# Trying to convert a non-numeric string to an integer2user_input = "hello"3number = int(user_input)4print(number)1# Fix: Validate the input before conversion using try/except2user_input = "hello"3 4try:5 number = int(user_input)6 print(f"Converted number: {number}")7except ValueError:8 print(f"Error: '{user_input}' is not a valid integer. Please enter a number.")9 10# Alternative: Check with str.isdigit() first11if user_input.isdigit():12 number = int(user_input)13else:14 print("Input is not a valid number.")Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
The `int()` function accepts a string, but the string `"hello"` cannot be parsed as a base-10 integer. Python raises `ValueError: invalid literal for int() with base 10: 'hello'`. The type is correct (string), but the value cannot be meaningfully converted.