1. Excited echoTo do
Ask the user for some text, then print it back followed by !!! with no space before the exclamation marks.
| Input | Output |
|---|---|
| python | python!!! |
| Hi there | Hi there!!! |
Module 0 · Functions, Variables · Lesson 2 of 5
A variable is a name that holds a value so you can use it later. The = sign is assignment: Python works out the right side first, then stores it in the name on the left.
name = input("What's your name? ")
print("hello,", name)
input shows a prompt, waits for the user to type, and returns what they typed. It always returns a str, even when the user types digits.
There are a few ways to combine text:
"hello, " + name glues strings together (you add the space yourself).print("hello,", name) passes two arguments, so print adds the space.Pick names that say what they hold: name, total, price. Future you will thank you.
When you click Run below, a cursor appears in the terminal when your program asks for input. Type and press Enter.
The user types 42 for x = input(). What type is x?
What does this print? x = "cat" x = "dog" print(x)
What does print("hi" + "there") show?
Ask the user for some text, then print it back followed by !!! with no space before the exclamation marks.
| Input | Output |
|---|---|
| python | python!!! |
| Hi there | Hi there!!! |
Ask for a first name, then a last name (two separate input calls). Print them as Last, First.
| Input | Output |
|---|---|
| Ada ⏎ Lovelace | Lovelace, Ada |
| Grace ⏎ Hopper | Hopper, Grace |