A computer follows instructions exactly, and it never guesses. In this course you give your first instructions: you show a message, do a sum, control how the output looks, and fix a mistake by reading what Python tells you. You finish with a small project, and every lesson has practice that checks your work for you.
5 lessons, about 2 h 25 min5 simulations15 problems10 practice questionsPython in every lesson
Every program on this site runs in a code box in your browser, with nothing to install. A code box has the code, the buttons Run, Reset and Copy, an Input box for the answers to input(), and an output area for the results and the error messages. Change the code and press Run as often as you like. Press Reset to go back to the first code. Use straight quotation marks, and refresh the page if Python fails to load.
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.
Quotation marks make text, which print() shows as it is. Without quotation marks, Python calculates a sum and shows the answer. print() puts one space between pieces that are separated by commas. The option sep changes what goes between the pieces, and end changes what comes after the last piece. An empty print() makes a blank line. Text can use single or double quotation marks, and a new line inside text is written with a backslash and the letter n.
Python is strict about spelling and punctuation. When something is wrong, it stops and shows an error message with the line number, the kind of error, and often a hint. Typical mistakes are a capital letter in print, a missing quotation mark, and a missing bracket. Read the message from the last line up, find the line, fix one thing, and run again. Fix one error at a time, because a later error may be only a result of an earlier one.
In this project we print a name card with a border. We plan the card on paper, write each line with print(), use text times a number to repeat a character for the border, and check that every line has the same width. We then change the card for another person by changing only a few lines. The project uses print(), text, sums, comments, and the habit of running after each small step.
Log in to join the discussion.
Loading…