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.
Answer and explanation
Concise answer
number = int(userInput) number = number + 8 result = str(number)
Why this is correct
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.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
