1 / 12
🐍

Inputs in Python

Learn how to request and store information from users in your programs

💡

What are inputs?

Inputs let us type something into the computer so it can use our answers in the program.

🎯

Why do we use inputs?

  • So the computer can ask us questions and use our answers to do different things.
💻 Example
name = input("What is your name? ")

This code asks a user to enter their name. The user's input will be stored in the variable: name

name = input("What is your name? ").lower()

The addition of .lower() means that the user's input will be converted to lower case, this is beneficial for comparing values.

name = str(input("What is your name? "))

The addition of str() means that users can only enter a string value. Other data types will not be accepted.

Inputs can be set to exclusive for other data types by using either: int, float, or bool in the same way.



Question 1

What does this code do?

name = input("What is your name? ")
Question 2

Complete the code to request a user to input their age:

age = ______"What is your age?"_
Question 3

What is age here?

age = input("What is your age?" )
Question 4

What's wrong with this code?

input("What is your date of birth?" )
Question 5

Write the code for an input assigned to the variable eye_colour, that asks "What is your eye colour? ":

Question 6

Can characters or words be enterred here?

code = int(input("Please enter your code: "))
Question 7

What data type can be entered here?

cash_deposit = float(input("How much cash would you like to deposit? "))
Question 8

What is this code missing?

message = ("Type your message here: ")
Question 9

What does the .lower() method do?

name = input("Type your name: ").lower()
Question 10

Why do we use .lower()

🎉

Excellent Work!

You've mastered Python inputs!

🏆

Inputs Expert

You can now create and use inputs in Python

What's Next?

Continue your Python journey with control flow!