Variables, Types & Operators · Question 3 · Easy

A roll number typed as text is converted before adding. What is printed?

roll = "42"
print(int(roll) + 8)
  1. 428
  2. 50
  3. TypeError
  4. 50.0
Answer and explanation

Answer: B. 50

Explanation: int("42") converts the string to the integer 42, and 42 + 8 = 50. Without the conversion, adding a string and an integer would raise TypeError.

Previous: Riya shares 17 chocolates equally among 5 friends and keeps the leftovers… · Next: Which of the following is a valid Python variable name?

Practise variables, types & operators

Try a fresh set of variables, types & operators questions with an explanation after every answer, free and without signing up: Variables, Types & Operators practice. Or sit a full placement mock test.

More variables, types & operators questions

More python practice

Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge