Solution Design There is no surprising design to the solution. It is a straightforward four-line program:
1. Print the text, ―Hello, world!‖
2. Print the text, ―What is your name?‖
3. Let the user enter their name and store this in a variable.
4. Print the text ―Hello,‖ followed by their name.
The program calls Python’s print() function to display string values on the screen. As always,
the quotes of the string aren’t displayed on the screen because those aren’t part of the string value’s
text, but rather mark where the string begins and ends in the source code of the program. The
program calls Python’s input() function to get the user input from the keyboard and stores this in a
variable.
The + operator is used to add numeric values like integers or floating-point numbers together,
but it can also create a new string value from the concatenation of two other string values.
Special Cases and Gotchas Make sure that there is a space before printing the user’s name. If the user entered ―Alice‖, the
program should print 'Hello, Alice' and not 'Hello,Alice'.
Now try to write a solution based on the information in the previous sections. If you still have
trouble solving this exercise, read the Solution Template section for additional hints.
Solution Template Try to first write a solution from scratch, But if you have difficulty, you can use the following
partial program as a starting place. Copy the following code from https://invpy.com/helloworld-template.py and paste it into your code editor. Replace the underscores with code to make a working program:
# Print "Hello, world!" on the screen: ____('Hello, world!')
# Ask the user for their name: ____('What is your name?')
# Get the user's name from their keyboard input: name = ____()
# Greet the user by their name: print('Hello, ' + ____)
The complete solution for this exercise is given in Appendix A and https://invpy.com/helloworld.py.
You can view each step of this program as it runs under a debugger at https://invpy.com/helloworld- debug/.