1) c. Formatting output Examples




Kay wants to collect all of his friends’ body heights. He needs a statement for his code that prints ‘Insert your body height in cm:’ followed by 256 underscore ‘_’ symbols. How can he do that in an easy way?

1
2
Output:
Insert your body height in cm:________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________




Kay has been very curious and measured all of his new friends’ body heights as decimal numbers. For instance, Jay is 158.6cm tall, May is 161cm tall and so on. He needs to print these numbers on newlines otherwise nobody will understand! How can he do that?

1
2
3
4
5
Output:
161
158.6
160.7
164




Kay also collected his friends’ answers and realized that they were confusing : with their names missing and he now needs to write a statement in python that prints their names and heights separated by a tab character and one person per line. How shall he do it?

1
2
3
4
5
Output:
May:     161
Jay:     158.6
Kay:     160.7
Aay:     164




Kay wants to print his phone number with python. However, he wants to cheat and let only the very sharp-eyed ones read see his number. Write a statement that prints 100 blank spaces first and then Kay’s phone number.

1
2
Output:
                                                                                                    124816




There are more ways that Python allows you to format your output. You will learn more advanced ways of formatting output as we progress through more chapters. Go from complete beginner to master.



A note to visitors:

BTW, what if you have a hectic, mind-numbing job and you’re tired at the end of the day? In this condition, would you like to spend a couple of hours everyday so you learn Python fast? Maybe sacrifice your hobbies / personal plans / family time in the process? …wouldn’t that be a pain!

That is why the Python 3 Engager course has been designed to have 45 minute study sessions. Most lessons can be consumed in more or less 45 minutes, which is the ideal length of a study session according to research.

Chomp on these delicious lessons in 45 minute capsules. Are you done with a lesson? Then feel free to take a break or even call it a day!

Keeping your learning enjoyable like this goes a long way towards maintaining a balance in your life and your motivation up! Practice maintaining a balance like this and you can learn anything with little effort!

Get your full version of the Python Engager course today!