A developer writes a script that prompts the user for their age and stores it in a variable. Which code snippet correctly converts the input to an integer?
Trap 1: age = int(input)
input is not called, just passed to int.
Trap 2: age = input("Enter age: ", int)
input() does not accept a type as second argument.
Trap 3: age = input(int("Enter age: "))
int() is applied to the string, not to the input.
- A
age = int(input)
Why wrong: input is not called, just passed to int.
- B
age = int(input("Enter age: "))
Correctly converts the input string to an integer.
- C
age = input("Enter age: ", int)
Why wrong: input() does not accept a type as second argument.
- D
age = input(int("Enter age: "))
Why wrong: int() is applied to the string, not to the input.