Course 1.1Lesson 2 of 5
A program is a list of instructions that a computer follows from the top to the bottom, exactly as written. Python is a programming language that reads almost like English. print() is a function that shows something on the screen. The words inside quotation marks are shown as they are, and a sum without quotation marks is worked out. A line that starts with # is a comment, which Python skips, and which is a note for people.
Try the code and the simulations beside the lesson.
After this lesson you can
print() lines,print() line does, andThink about a recipe. It is a list of steps in a fixed order: wash the rice, add water, boil, wait. A person can guess what you mean if a step is a little unclear. A computer cannot. It does exactly what the list says, in the order of the list, and it never guesses.
A program is such a list of instructions. We write it in a programming language. Python is one. It reads almost like English, so it is a good first language, and many scientists, students and companies all over the world use it.
print().print is the name of a function. A function is a ready-made helper that does one job. This one shows something on the screen.( ) hold what we give to the function." " mark the start and the end of a piece of text. The text between them is shown exactly as you typed it. The quotation marks themselves are not shown.2 + 3 has no quotation marks, so Python works it out and shows the answer, 5.print() that there are two things to show. It puts one space between them.Python runs the lines from the top to the bottom. If you change the order of the lines, you change the output.
Swap two lines in the code box and run it. The two lines of output swap places too.
A line that starts with # is a comment. Python skips it. A comment is a note from you to a person who reads the program, and that person is often you, a month later.
Look at the first line of each program above. It is a comment. It says what the program does. Writing a comment is a good habit from the first day.
print(Hello) is an error, because Python looks for something called Hello.Print or PRINT. The name is print, in small letters.print "Hello" is an error in Python 3.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() shows things on the screen. Text goes inside quotation marks.# is a comment, and Python skips it.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
print() lines, what changes?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.