Exam-style question
Try this first
Write Python 3 statements that take the string userInput containing a whole number, convert it to an integer, add 8, and convert the result back to a string stored in result.
Model answer
What a good answer should say
- number = int(userInput) number = number + 8 result = str(number)
Explanation
Why this works
The first statement performs string-to-integer conversion. The addition is then carried out on the integer.
The final statement performs integer-to-string conversion and stores the resulting string in result.
Common mistake
No common mistake is linked to this question yet.
