Exercise 9. Printing, Printing, Printing

By now you should realize the pattern for this book is to use more than one exercise to teach you something new. I start with code that you might not understand, then more exercises explain the concept. If you don’t understand something now, you will later as you complete more exercises. Write down what you don’t understand, and keep going.

ex9.py


 1    # Here's some new strange stuff, remember type it exactly.
 2
 3    days = "Mon Tue Wed Thu Fri Sat Sun"
 4    months = "Jan Feb Mar Apr May Jun Jul Aug"
 5
 6    print("Here are the days: ", days)
 7    print("Here are the months: ", months)
 8
 9    print("""
10    There's something going on here.
11    With the three double-quotes.
12    We'll be able to type as much as we like.
13    Even 4 lines if we want, or 5, or 6.
14    """)

What You Should See

Exercise 9 Session


$ python3.6 ex9.py
Here are the days:  Mon Tue Wed Thu Fri Sat Sun
Here are the months:  Jan
Feb
Mar
Apr
May
Jun
Jul
Aug

There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.

Study Drills

Check your work, write down your mistakes, try not to make them on the next exercise. Are you breaking your code and then fixing it? In other words, repeat the Study Drills from Exercise 7.

Common Student Questions

Why do I get an error when I put spaces between the three double-quotes? You have to type them like """ and not " " ", meaning with no spaces between each one.

What if I wanted to start the months on a new line? You simply start the string with , like this:

" Jan Feb Mar Apr May Jun Jul Aug"

Is it bad that my errors are always spelling mistakes? Most programming errors in the beginning (and even later) are simple spelling mistakes, typos, or getting simple things out of order.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
44.197.114.92