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?✗ Incorrect
input() always returns a string, so typing 123 returns "123".How do you show a prompt message before input?
✗ Incorrect
Passing a string inside
input() shows it as a prompt.Which code correctly stores user input in a variable?
✗ Incorrect
You assign the result of
input() to a variable like name = input().How to convert input to an integer?
✗ 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())?✗ 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.