Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the input() function do in Python?
The input() function waits for the user to type something and press Enter. It then returns what the user typed as a string.
Click to reveal answer
beginner
How do you store user input in a variable?
You assign the result of input() to a variable like this: name = input(). Now name holds the text the user typed.
Click to reveal answer
beginner
How can you show a message to the user before taking input?
You can pass a string to input() like this: input('Enter your name: '). This message appears before the user types.
Click to reveal answer
beginner
What type of data does input() return?
input() always returns a string, even if the user types numbers. You need to convert it if you want another type.
Click to reveal answer
beginner
How do you convert user input to an integer?
Use the int() function like this: age = int(input('Enter your age: ')). This changes the input string to a number.
Click to reveal answer
What does input() return when the user types 123?
AError
B123 (an integer)
C"123" (a string)
DNone
✗ Incorrect
input() always returns a string, so typing 123 returns "123".
How do you show a prompt message before input?
Ainput() + 'Enter your name: '
Binput('Enter your name: ')
Cprint('Enter your name: ')
Dprompt('Enter your name: ')
✗ Incorrect
Passing a string inside input() shows it as a prompt.
Which code correctly stores user input in a variable?
Aname() = input
Binput = name()
Cinput(name)
Dname = input()
✗ Incorrect
You assign the result of input() to a variable like name = input().
How to convert input to an integer?
Aint(input())
Bstr(input())
Cfloat(input())
Dinput(int())
✗ Incorrect
Use int(input()) to convert the input string to an integer.
What happens if user types a non-number and you use int(input())?
AProgram gives an error
BInput is converted to 0
CInput is ignored
DInput is converted to string
✗ Incorrect
Trying to convert non-numeric input to int causes an error.
Explain how to take user input and store it in a variable with a prompt message.
Think about how to show a message and save what user types.
You got /3 concepts.
Describe how to convert user input to a number and why it is necessary.
Remember input is text by default.
You got /3 concepts.
Practice
(1/5)
1. What does the input() function do in Python?
easy
A. It stops the program immediately.
B. It prints text on the screen.
C. It asks the user to type something and returns it as text.
D. It converts text to numbers automatically.
Solution
Step 1: Understand the purpose of input()
The input() function waits for the user to type something and press Enter.
Step 2: Identify what input() returns
It always returns the typed data as a string (text), not numbers or other types.
Final Answer:
It asks the user to type something and returns it as text. -> Option C
Quick Check:
input() returns text [OK]
Hint: Remember: input() always returns text, never numbers directly [OK]
Common Mistakes:
Thinking input() prints text
Assuming input() stops the program
Believing input() converts text to numbers automatically
2. Which of the following is the correct way to ask the user for their name using input()?
easy
A. name = input Enter your name:
B. name = input('Enter your name: ')
C. name = input['Enter your name:']
D. name = input{Enter your name:}
Solution
Step 1: Check the syntax of input() with prompt
The prompt must be inside parentheses and quotes, like input('prompt').
Step 2: Identify the correct option
Only name = input('Enter your name: ') uses parentheses and quotes correctly to show the prompt.
Final Answer:
name = input('Enter your name: ') -> Option B
Quick Check:
Prompt text inside parentheses and quotes [OK]
Hint: Use parentheses and quotes for prompt text in input() [OK]
Common Mistakes:
Missing parentheses around prompt
Using brackets or braces instead of parentheses
Not putting prompt text inside quotes
3. What will be the output of this code if the user types 25 when asked?
age = input('Enter your age: ')
print(age + 5)
medium
A. 30
B. 255
C. 5
D. TypeError
Solution
Step 1: Understand input() returns a string
The variable age will be the string '25', not the number 25.
Step 2: Analyze the print statement
age + 5 attempts to add a string and an integer. In Python, this causes a TypeError, but if the code was print(age + '5'), it would concatenate to '255'. Since the code is print(age + 5), it raises a TypeError.
Final Answer:
TypeError -> Option D
Quick Check:
String + int causes TypeError [OK]
Hint: input() returns text; convert to int before adding numbers [OK]
Common Mistakes:
Assuming input() returns number
Trying to add int to string without conversion
Expecting automatic type conversion
4. Find the error in this code snippet:
number = input('Enter a number: ')
result = number * 2
print(result)
medium
A. number is a string, multiplying repeats text instead of doubling number
B. input() should be replaced with print()
C. Missing parentheses in print statement
D. No error, code works fine
Solution
Step 1: Identify the type of number
The input() function returns a string, so number is text.
Step 2: Understand what number * 2 does for strings
Multiplying a string by 2 repeats it twice, so if user types '3', result is '33', not 6.
Final Answer:
number is a string, multiplying repeats text instead of doubling number -> Option A
Quick Check:
String * 2 repeats text, not math multiply [OK]
Hint: Convert input to int before math operations [OK]
Common Mistakes:
Assuming input returns number
Expecting string * 2 to double value
Ignoring type conversion
5. You want to ask the user for two numbers and print their sum. Which code correctly does this?
hard
A. a = int(input('First number: '))
b = int(input('Second number: '))
print(a + b)
B. a = input('First number: ')
b = input('Second number: ')
print(a + b)
C. a = input('First number: ')
b = input('Second number: ')
print(int(a) + b)
D. a = input('First number: ')
b = int(input('Second number: '))
print(a + b)
Solution
Step 1: Convert inputs to numbers
To add numbers, convert both inputs from strings to integers using int().
Step 2: Add the converted numbers
Only a = int(input('First number: '))
b = int(input('Second number: '))
print(a + b) converts both inputs before adding, so it sums correctly.
Final Answer:
a = int(input('First number: '))
b = int(input('Second number: '))
print(a + b) -> Option A