9. Say hello
Your program reads one line: a person's name. Print the greeting Hello, <name>!, with the name in place of
<name>: the word Hello, a comma, a space, the name, then !.
Remove any spaces before and after the name first. Spaces inside the name stay, and so does every letter, including
letters such as ë or é.
Example 1
AdaHello, Ada!Example 2
GraceHello, Grace!Example 3
Ada LovelaceHello, Ada Lovelace!Constraints
- The name has 1 to 50 characters, not counting the spaces around it.
- It can hold letters from any language, and spaces.
- Print nothing else. A prompt inside
input()is fine: the tests leave it out of the output.
Submit also runs 3 more tests you can't see.
Practises String Formatting Deep Dive (lesson 24).
name.strip()removes the spaces at the start and end of a string and leaves the ones inside it alone.- An f-string puts a variable inside text:
f"Hello, {name}!". - Check the punctuation: a comma and one space after
Hello, and!straight after the name.
Solve it without hints for 3 stars, with hints for 2, after seeing the solution for 1.
One way to solve it, once you've had a go.
Solving it after seeing the solution earns 1 star.
Your Submits show here, with their code, so you can go back to one. They stay in this browser.
# Read a name and print "Hello, <name>!". # Remove the spaces around the name first. name = input()
Run your code to see how it does on the test cases, or Submit to check every test.