logo

Question detail

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.

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

Question

Type

practice

Style

Topic

Programming

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.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.