Question
Can you give an example of code that causes 'ValueError: invalid literal for int() with base 10'?
Asked by: USER7581
97 Viewed
97 Answers
Answer (97)
```python
number_string = "abc"
try:
number = int(number_string)
except ValueError as e:
print(f"Error: {e}")
```
This code attempts to convert the string 'abc' to an integer, which is not a valid decimal representation, causing the ValueError.