Learning Python Basics in 6 days — Day 2

Day 2

Welcome back, hopefully, you took some time to practice what you learned from yesterdays tutorial. In today’s tutorial, we are going to be working with more printing and asking the user for input and setting the input equal to a variable.


For this first example, we are going to work with the format method as well as observe how Python treats multiplication of string value and an integer.

On line 2 we use the format method and insert the word “snow” into the {} braces. Then on line 4 we the string “.” and multiply this by the integer 10.

On line 20 concatenate each of the strings using the plus (+) operator. At the end of the print statement, we use the argument end=’ ‘, the program will actually print both statements on the same line.

Below is the output from the program above:

The multiplication of a string by an integer gives us a return of that string 10 times. If we were to multiply the string by 5 it would have returned 5 “.”. Also, observe that Cheese Burger was printed on the same line due to the end=’ ‘.


In this example, we are going to be working the format method again but this time there is a wrinkle with the way we define the {} braces.

We set the variable formatter equal to a string of {} braces. This will allow us to call the format method on the variable and then pass it, string values, booleans, integers, or floats. We can observe on line 6 that we pass into the variable formatter, 4 times. This should give us a return value of 16 {} braces.

Below is the output from the example above:

Take some time to think about the output on line 4. The first time a completed this example it took me some time to really understand why we were getting back 16 {} braces.


In this example, we are going to introduce how to print a string to a new line although it is on the same string.

On line 4 we use ‘\n’, this allows us to print everything after it to a new line. So when we call months on line 7, Jan and the subsequent months should be printed on their own line.

On lines 9–14 we use the triple quotes, which allows us to type on a new line.

The output should be as follows:

Observe how the string in lines 9–14, has the output of printing each line that is was typed on in the program above.


In this example, we going to work with more with the ‘\’.

On line 1 we use the ‘\t\’, this will tab in the sting when it is printed. On line 2 we use the ‘\n’ again which will print everything after on its own line. Then on line ‘\\’, we have to use a double backslash this tells Python we actually want to display a backslash.

Then on line 5–10, we combine what we have learned from this example as well as the last.

The output should be as follows:

Hopefully, while you were typing out the example above you were already think about how the output would look on the command line.


In this example, we will ask the user for input when running our script. Programming a computer would be very useful if had to manually enter all the data for each program. Luckily for us, computers are very good at taking in user input and creating useful programs.

On line 1 we use the argument end=’ ‘, this will allow us to call the input method from line 2 onto line 1 when it is printed. We capture the input and store it into the variable age, we will use each of our defined variables and print them into the formatted string on line 8. Take your time, this example can be tricky at first but if you break down into small pieces I know you can understand it.

Below is the output from the example above:

When you run the program, Python will ask to enter your information. You then will type in your own information: age, height, and weight.


In today’s last program we are going to create the same output as the ex11.py, but we are going to do it in fewer lines of code. Remember when I told you that there is more than one way to get the same result but only one right way. This example will clarify why Python is such a great language to learn.

Use the input method will allow prin the question to command line. We can this store the answer to the question directly to the variable all on the same line.

The output should be same the result as ex11.py: