Course 1.1Lesson 5 of 5
In this project we print a name card with a border. We plan the card on paper, write each line with print(), use text times a number to repeat a character for the border, and check that every line has the same width. We then change the card for another person by changing only a few lines. The project uses print(), text, sums, comments, and the habit of running after each small step.
Try the code and the simulations beside the lesson.
After this lesson you can
print() lines,We want a name card like this one:
+------------------------+
| Name : Asha |
| Class : 7B |
| School : Green Hill |
+------------------------+It is only text, but it is a good first project, because every line has to be exactly right.
Before you type, look at the card.
|.A plan like this saves time. It is easier to fix a plan than to fix a program.
A beginner writes the whole program at once and cannot find the mistake. A programmer writes one or two lines, runs, looks, and goes on. Start with only the top line.
Typing 24 dashes is slow, and you may count wrong. Python can repeat text for you: text times a number repeats the text.
The whole program is here.
A text times a negative number is empty. So when the name is too long, no spaces are added, and the line sticks out.
Look at the output and compare it with your plan. Check three things.
| line up in one straight column on the right?If the right edge is crooked, one line has too few or too many spaces. Count the characters of that line.
A project is yours only when you change it. Do these, one at a time, and run after each one.
City.* or =.Start with two quick questions. Each New numbers gives you a fresh one, so you can practise as long as you like.
Then the labs and the problems:
print(), like the lab A house made of text, and make the roof wider with a repeat."-" * 24 repeats a character. Use it, instead of typing a character many times.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
"=" * 5 give?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.