• Welcome to Python Sequencing Puzzles Part 1 Python Conventions Sequencing Puzzles Part 2 Review and Quiz Unit 1 Project

Welcome to Python 1



Next
© Tynker, 2020

Introduction to Python

In this course, you'll learn the basics of Python, a programming language that's used by millions of people around the world. Python is a great first programming language to learn, because it's powerful, simple, and flexible. And it's used by professional engineers at places like Google, NASA, and IBM.

Computers don’t yet understand human languages like English or Spanish. That means human operators need to write instructions for a computer to follow in a language that computers can understand. These are called programming languages.

Programming languages start with a set of well-defined terms such as IF or DISPLAY. Programmers can take these terms and put them together to make what is called a programming statement, such as DISPLAY (3 + 4). A collection of programming statements is called a code segment. A Computer Program is a collection of code segments that performs a specific task when run by a computer. So really, when you are using any kind of software, your computer is running a computer program!

APCSP

Python isn’t the only programming language out there. Dozens and even hundreds of programming languages have been invented over the years. But once you understand one programming language, you’ll be able to learn others easily.

Here is an example of Python code that prints all the numbers from 0 to 9.

Previous Next
© Tynker, 2020

About The Course

The course is organized into a series of Units. Each unit is broken into chapters. You can skip around if you like, but it is recommended that beginners follow this course sequentially: Each challenge builds on the last, and they grow in complexity as the course progresses.

Unit 1. Syntax and Sequencing Learn how to make simple function calls, and how to give instructions in Python. String function calls together to solve linear programming puzzles.

Unit 2. Loops and Patterns Build on your Python knowledge by creating loops. Learn how to include for loops in your programs and how to repeat necessary code.

Unit 3. Conditional Logic In this unit, you will learn how to branch code. How to run specific commands as you run into different problems.

Unit 4. Conditional Loops Combine your knowledge of loops and conditionals to create loops that are even more powerful than just repeating code a set amount of times.

Unit 5. Variables Learn how to store information within programs. Explore how to receive input from users and how to handle the data.

Unit 6. Data Types and Expressions In this unit, investigate the different types of variables that exist in Python and how each one can help you write programs. Learn how to combine variables and data to create expressions.

Unit 7. Turtle Graphics Learn how to draw with Python. Using turtle graphics you will be able to combine all of your knowledge to create beautiful artwork, with code!

How to complete each lesson

  • Read each module carefully and experiment with the programs we give you
  • Solve all programming problems and answer all questions in the module before moving on
  • Take the quiz at the end of the lesson

New concept: Introduces a new term or idea.

General idea: Shows a diagram of a short Python snippet.

Puzzles: Programming challenges that test your program and give immediate feedback on whether your solution works.

Project: Be creative with these programs - there is more than one way to solve a problem!

Previous Next
© Tynker, 2020

The Programming Window

Below you will see the Tynker inline code editor. It is divided into two sides.

The Code window, is where you will be typing and editing your code. Throughout this course the Code window will be either editable or read-only (as seen here).

The Preview window, is where you will see the output or product of your code. You will also interact with the running program in the Preview window.

To see what the code does you will need to execute the program. Executing a program means you will send your instructions to the computer, and it will read and act on the instructions provided. In this course, you will do this by clicking the "run" button in the Preview window.

Notice how when you click "run" the Console window appears. This is a special area in the Preview window that will allow you to see your programs output. In this case, the output is, "Welcome to Python." You can open and close the Console window by clicking it at the bottom of the Preview window.

Previous Next
© Tynker, 2020

Output

Humans need to be able to communicate with computers. And computers need to give humans like you information back too.

Computer programmers call this idea input and output. You put information inside your computer using input devices like your keyboard or mouse. Even gestures like "shake to undo" on smartphones can be considered input. If you control your phone or computer with voice commands, you guessed it: That microphone is another example of input!

You get information from your computer by watching your screen or listening to the computer's speaker. This is called the output of the computer. Some people even print their documents—this is another example of output.

Values

A value is a unit of information, like a number or basic text. To pass a value to a instruction, you will type it between the parentheses.

Here the value is the number 42.

A value can also be basic text enclosed in quotation marks (").

DIY: Your First Output

Use a print() instruction to display your first name.

Previous Next
© Tynker, 2020

Functions

The word print is the name of a function, an action that the computer knows how to perform. Just as humans have certain actions they know to perform like "eat" and "sleep", computers have an extensive set of known actions that they can perform.

What's a Function?

A function is a set of instructions that are organized into one action. It is a shortcut, or a way of organizing code into a general tool that you can use again and again.

In Python and many other programming languages, functions are signified by using parentheses () that follow the function name. You may see functions also referred to as methods.

What's a Function Parameter?

Parameters are the values sent to a function, inside the parentheses (). These may also be called arguments. Not every function takes parameters, but many do. Parameters allow you to take finer-grained control of the function's behavior.

A function call is an instruction that tells the computer to perform a function with some value.

For example, consider the function call below:

The print() function takes numbers and text as input. It will then print the given value to the computer's console.

If you used a capital letter, that is, you wrote Print(42) — your code will not work, because in Python, only print() has been defined. So type carefully — capitalization matters.

In the code above, the function call tells the computer to perform the print() function with the value "Code is everywhere!". Every computer performs the print() function by displaying the given value as output.

Multiple Instructions

A sequence of instructions is called a program, and is sometimes referred to as code.

Most programs have more than one instruction. Each instruction is written on a separate line.

When a computer executes a program, it performs each instruction in the program one-by-one.

DIY: Use the print() Function

Print the name of your favorite author, artist, and historical figure on separate lines.

Previous Next
© Tynker, 2020

Syntax and Debugging

Just like with English, Python has its own grammar called syntax. Code that does not follow Python's syntax will produce a syntax error.

Debugging is the process of fixing broken code. Let's take a look at some broken code and see if you can debug it.

Syntax Errors

Syntax Errors happen when Python can't understand the program, often due to a missing or misplaced symbol. In these puzzles you'll have to debug the faulty code in order to reach the goal.

Parentheses Are Required

A function call must have an open and closed parentheses around its arguments.

Fix the function call by reading the error message and making the necessary correction.

Spacing

Spaces between values, or in function calls, won't affect how the computer interprets the instruction.

Missing Symbols

A syntax error can often be the result of a misplaced, or missing, symbol.

Fix the function call by reading the error message and making the necessary correction.

Valid Arguments

A function call requires a valid argument. In this case, hello is being interpreted as code, not basic text. Add quotation marks around hello to indicate it should be interpreted as a string.

Functions Must Exist

A function name must be a known action. In this case, display() is not a known function. Change the name of the function below to print.

Unseen Errors

Sometimes a problem with a program is not caught by the computer. In this case, each line is programmed correctly, but the sequence is off.

Fix the order of the print statements to correct the outputted sentence.

DIY: Fix the Bugs, Print the Boat

Try debugging the boat printed below by fixing any syntax and sequencing errors of the print() statements.

Hint

Add a ) to the first statement, and a " to the final statement. Then swap the third and fourth print() statements to make the boat print correctly. This is an example of a logical error: The program will run, but it doesn't display what you want unless you change the order or your code instruction.

DIY: Fix the Haiku

Can you fix the program below to print the haiku?

Previous Next
© Tynker, 2020

Review

Let's review what you've learned so far.

Output

One of the most common instructions you will give a computer is to display some information. This can be performed in Python with the print() function.

Values

A value is a unit of information, like a number or basic text encased with " quotation marks.

Function Call

A function call is an instruction that tells the computer to perform a function with some value.

Arguments

When a value is used in a function call, it is called an argument. Arguments are enclosed in parentheses after the function name.

Multiple Instructions

A sequence of instructions is called a program, and is sometimes referred to as code.

Most programs have more than one instruction. Each instruction is written on a separate line.

When a computer executes a program, it performs each instruction in the program one-by-one.

Debugging

Debugging is the process of fixing broken code.

Previous Done
© Tynker, 2020
Sign in
Don't have an account?