Questions: Type Conversion and Casting

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A Python program prompts the user to enter their age and then adds 1: age = input('Enter your age: ') + 1. What happens when the user types '25'?

AThe program returns 26, because Python automatically converts the string to an integer
BThe program raises a TypeError, because you cannot add an integer to a string
CThe program returns '251', concatenating the string with the integer
DThe program returns 25, because addition is undefined between a string and integer
Question 2 Multiple Choice

What does int(7.9) evaluate to in Python?

A8, because int() rounds to the nearest integer
B7, because int() truncates toward zero
C8.0, because the result remains a float
DA ValueError, because 7.9 is not a valid integer representation
Question 3 True / False

int('3.14') successfully converts the string '3.14' to the integer 3 in Python.

TTrue
FFalse
Question 4 True / False

Any value entered by a user at the keyboard arrives in a Python program as a string, regardless of what they typed.

TTrue
FFalse
Question 5 Short Answer

Why does int('3.14') fail in Python, and what is the correct two-step approach to convert the string '3.14' to the integer 3?

Think about your answer, then reveal below.