Description section points out that your solution shouldn’t call it.
I recommend solving the exercises in this book repeatedly until it becomes effortless. If you can
solve an exercise once, try solving it again a couple of weeks later or without looking at the hints in
the later sections. After a while, you’ll find yourself quickly being able to come up with strategies to
solve these exercises.
Let’s begin!
5
E X E R C I S E # 1 : H E L L O , W O R L D !
print('Hello, world!')
→
Hello, world!
―Hello, world!‖ is a common first program to write when learning any programming language. It
makes the text ―Hello, world!‖ appear on the screen. While not much of a program, it serves as a
simple test for whether the programmer has the language interpreter correctly installed, the computer
environment set up, and a basic understanding of how to write a complete program.
This exercise adds an additional step to collect keyboard input from the user. You’ll also need to
concatenate (that is, join together) string values to greet the user by name. The exercises in this book
are for those with some experience writing programs, so if this exercise is currently beyond your skill
level, I’d recommend reading some of the beginner resources I discussed in the Prerequisites section
of the Introduction.
Exercise Description
Write a program that, when run, greets the user by printing ―Hello, world!‖ on the screen. Then it
prints a message on the screen asking the user to enter their name. The program greets the user by
name by printing the ―Hello,‖ followed by the user’s name.
Let’s use ―Alice‖ as the example name. Your program’s output should look like this:
Hello, world!
What is your name?
Alice
Hello, Alice
Try to write a solution based on the information in this description. If you still have trouble
solving this exercise, read the Solution Design and Special Cases and Gotchas sections for
additional hints.
Prerequisite concepts: print(), strings, string concatenation
Python Programming Exercises, Gently Explained
6
Dostları ilə paylaş: |