Exercise - Build a program to say Hello
Now let's use what you learned about
input, and string concatenation to display a personalized greeting using a Python script.
Start the online code editor by typing
codeat the terminal prompt.
Type or paste the following statements into the editor.
print('Welcome!') name = input('Enter your name: ') print('Hello, ' + name)
Save the file as hello.py. You can click the ellipse "..." in the right corner of the cloud editor, or use the accelerator key (Ctrl+S on Windows and Linux, Cmd+S on macOS).
Close the editor through the "..." context menu.
You can verify the file is on disk using the
Execute the script using the Python interpreter.
When prompted, type your name and press Enter.
Confirm that a personalized greeting appears in the output:
Welcome! Enter your name: Hannah Hello, Hannah
If you want to add an exclamation mark after the name so the greeting reads
"Hello, Hannah!", how would you do it?
A single Python statement can use multiple
+ operators to concatenate several strings.
Modify the program to add an exclamation point to the end of the output and run the app to verify the results.