Printing and Comments
0 / 6
In this course we will teach you basics of writing simple
programs in Python.
Printing
Below is a one line program that outputs the number 10.
Go ahead and click the Run button to see the output of the program.
Go ahead and click the Run button to see the output of the program.
Here is a multi-line program that will print several numbers:
Notice that each number gets printed on a new line.
If you want the numbers to be printed on the same line you can do this:
Notice that 1, 2 and 3 are printed on the first line and 4 and 5 are printed on the next line.
You can also do math with numbers and then print the results:
Your turn. The program below should print the following:
but it doesn't work because it has bug.
A bug is anything in your code that makes your program run incorrectly.
First, run the code below to see what error the bug is causing.
Then, identify and fix the bug in the code so that your output matches the expected output.
1 2 3 4 5 6 7 1 1 1 4 7 4 2
but it doesn't work because it has bug.
A bug is anything in your code that makes your program run incorrectly.
First, run the code below to see what error the bug is causing.
Then, identify and fix the bug in the code so that your output matches the expected output.
Expected Output
1 2 3 4 5 6 7 1 1 1 4 7 4 2
Your Output
Be sure you click the
view solution button
above to see a solution and additional information about the exersice.
Comments
You can also add comments
to your code.
A code comment is a note in the code that helps explain what it does but is ignored when the program runs.
In Python there are two types of comments
multi-line and single-line
Run the code below:
A code comment is a note in the code that helps explain what it does but is ignored when the program runs.
In Python there are two types of comments
multi-line and single-line
Run the code below:
Use ''' ''' for multi-line
Use # for single-line
Use # for single-line