What is input()?
In Python, input() pauses the program and waits for the user to type something. It returns the text entered as a string, which you can store in a variable and use later.
name = input("What is your name? ")
print("Hello " + name)
Here, the user’s response is stored in name and then printed in a greeting.
Task 1: Full Name & Object on Your Left
Print your first name and surname on the first line; on the next line print the name of the object (or person) beside you.
Example:
print("Elsie Parker")
print("Pencil Case")
Printing Over Multiple Lines
Use separate print() calls:
print("Welcome to....")
print("Computer Science")
print("Newbies!!!")
Or a single print with newline characters \n:
print("Welcome to....\nComputer Science\nNewbies!!!")
Task 2: Name, Favourite Colour, and Movie
Use \n to print your name, favourite colour, and favourite movie on separate lines.
Example:
print("Matthew\nyellow\nInterstellar")
Using Variables with input()
Capture input and then print it:
message = input("Enter a message: ")
print(message)
Tip: Don’t put quotation marks around variable names inside print().
Variables Task
Create three variables: one for your name, one for your favourite colour, and one for your favourite movie. Use input() to capture each, then print them on separate lines using a single print() with newline characters.
Example:
name = input("What is your name? ")
colour = input("What is your favourite colour? ")
movie = input("What is your favourite movie? ")
print(name + "\n" + colour + "\n" + movie)