0
0
Pythonprogramming~5 mins

Taking input using input() in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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
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: ')
Which code correctly stores user input in a variable?
Aname() = input
Binput = name()
Cinput(name)
Dname = input()
How to convert input to an integer?
Aint(input())
Bstr(input())
Cfloat(input())
Dinput(int())
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
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.