Intro to Python Programming

Similar documents
In this project, you ll learn how to use a turtle to draw awesome shapes and patterns.

You will be writing code in the Python programming language, which you may have learnt in the Python module.

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python.

LO: To recreate Matisse s Snail in Python

Art, Nature, and Patterns Introduction

Self-Teach Exercises: Getting Started Turtle Python

Animations involving numbers

Understanding the Screen

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

A cipher is a type of secret code, where you swap the letters around so that noone can read your message.

Chapter 7. Polygons, Circles, Stars and Stuff

Intro. Scheme Basics. scm> 5 5. scm>

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Honors Computer Science Python Mr. Clausen Program 7A, 7B

Polygons and Angles: Student Guide

3x - 5 = 22 4x - 12 = 2x - 9

61A Lecture 2. Wednesday, September 4, 2013

On the Web sun.com/aboutsun/comm_invest STAROFFICE 8 DRAW

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

Introduction to Flash - Creating a Motion Tween

Introduction to Programming with JES

61A Lecture 2. Friday, August 28, 2015

PYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment

Order from Chaos. Nebraska Wesleyan University Mathematics Circle

The >>> is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements.

Euler s Method with Python

Animations that make decisions

YCL Session 4 Lesson Plan

SPSS 11.5 for Windows Assignment 2

SKIP THIS STEP IF YOUR DISTRICT HAS CHROMEBOOKS FOR EVERY STUDENT WITH THEIR OWN GOOGLE APPS USERNAME!!!

[Video] and so on... Problems that require a function definition can be phrased as a word problem such as the following:

A First Look at Logo

Touring the Mac S e s s i o n 4 : S A V E, P R I N T, C L O S E & Q U I T

Create Turtles with Python

Order from Chaos. University of Nebraska-Lincoln Discrete Mathematics Seminar

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Create and edit word processing. Pages.

INTRODUCTION TO DRAWING WITH LOGO A

1 Getting started with Processing

ANSWER KEY. Chapter 1. Introduction to Computers

In this lesson, you ll learn how to:

CISC 1600 Lecture 3.1 Introduction to Processing

Using Dreamweaver CC. Logo. 4 Creating a Template. Page Heading. Page content in this area. About Us Gallery Ordering Contact Us Links

Decisions, Decisions. Testing, testing C H A P T E R 7

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Problem 1.1 (3 pts) :Python uses atomic data types and builds up from there. Give an example of: a. an int b. a double c. a string

Audacity Stereo Wave Recorder and Editor

Computer and Programming: Lab 1

Chapter 1. Getting Started

How Your First Program Works

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Shape and Line Tools. tip: Some drawing techniques are so much easier if you use a pressuresensitive

nostarch.com/pfk For bulk orders, please contact us at

Lab 5: File I/O CSE/IT 107. NMT Computer Science

Part II Composition of Functions

Pro-Bot

The Beauty and Joy of Computing 1 Lab Exercise 1: Introduction to Scratch/BYOB - Animations and Communication

T H E I N T E R A C T I V E S H E L L

UV Mapping to avoid texture flaws and enable proper shading

CMPSCI 119 LAB #2 Anime Eyes Professor William T. Verts

Make a Guessing Game with Python

Drawing a Circle. 78 Chapter 5. geometry.pyde. def setup(): size(600,600) def draw(): ellipse(200,100,20,20) Listing 5-1: Drawing a circle

CS 190C: Introduction to Computational Thinking

EEN118 LAB THREE. Section A - Conversions A1. Remembering how to start. A2. Exotic Canada

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

1: Introduction to Object (1)

Drawing Tools. Drawing a Rectangle

Unit Using Logo Year Group: 4 Number of Lessons: 4

The original image. Let s get started! The final result.

CoderDojo Activity Cards: The Cards (Animation2.html): How to use: Student comes to mentor, and together they choose a card to do next.

the NXT-G programming environment

How To Upload Your Newsletter

Learn to make desktop LE

textures not patterns

3Using and Writing. Functions. Understanding Functions 41. In this chapter, I ll explain what functions are and how to use them.

1.7 Limit of a Function

Designing Your Teacher Page. Medora Community School Corporation

Energy for Life Walkathon. Fundraising Website How-To - 3.2

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

: Intro Programming for Scientists and Engineers Final Exam

Creating Vector Shapes Week 2 Assignment 1. Illustrator Defaults

Assignment 1 What is a Computer?

Using Flash Animation Basics

ILLUSTRATOR. Introduction to Adobe Illustrator. You will;

CS 177 Recitation. Week 1 Intro to Java

S A M P L E C H A P T E R

How to use the Social care: a rewarding career for you tool

ASCII Art. Introduction: Python

DIRECTV Message Board

S A M P L E C H A P T E R

How to Make Your Content ADA Compliant

Welcome Back! Without further delay, let s get started! First Things First. If you haven t done it already, download Turbo Lister from ebay.

DESIGN YOUR OWN BUSINESS CARDS

Part 1. Summary of For Loops and While Loops

Chapter 1. Math review. 1.1 Some sets

If Statements, For Loops, Functions

Python, Part 2 CS 8: Introduction to Computer Science Lecture #4

Locate it inside of your Class/DreamWeaver folders and open it up.

QUICK EXCEL TUTORIAL. The Very Basics

Text Input and Conditionals

Transcription:

Intro to Python Programming If you re using chromebooks at your school, you can use an online editor called Trinket to code in Python, and you ll have an online portfolio of your projects which you can access from any computer! Go to Trinket.io: Sign up for a free account by clicking Sign Up at the top of the page. Once you re signed up your screen should look like this:

Click the big blue button to make a new Trinket and select Python. You ll get a screen with a blank editor (like a word processing document) on the left and an output window on the right:

It s easy to print text output in Python. Just type print hello world (or any text you d like to print) and press the Run arrow. You ll see your output on the right: Getting Started with Turtle Graphics But text output isn t the coolest thing you can do with Python. There was a programming language called Logo which was invented at MIT in the 1960s. It allowed users to draw geometric designs by making turtles walk around the screen using simple commands like

forward and right. Python copied that functionality into its turtle module which is installed by default when you download Python on your computer. Trinket supports all the Python turtle functions that you can find on the Python.org site: https://docs.python.org/3/library/turtle.html#module-turtle Or you can do a web search for python turtle and those docs should be the first link to come up. You ll find dozens of functions you can make the turtles do but we ll only need forward and left for this project. Importing modules People have written lots of code that a programmer could find useful, and they share them in files called modules, many of which are included in the Standard Library you get when you install Python. There are a few different ways to import modules, but the easiest way at this stage is to type from turtle import * to import all the turtle functions. Then you can give a turtle a command and when you click the Run arrow you ll see the results:

The forward function requires a number of steps or pixels you want the turtle to take. You can make the turtle look like a turtle by adding a shape command after the import. You can also change the color this way: Just by learning one more command, left, you can make the turtle draw all kinds of shapes. The left function requires a number of degrees you want the turtle to turn. left(90) makes it turn 90 degrees to the left:

Using only the forward and left functions, you can make the turtle walk around the screen in the shape of a square. You have to repeat your code a bunch of times, and the abbreviations fd and lt come in handy: Loops Every programming language has a way to tell the computer to repeat a block of code a specific number of times. This is called a loop, and it s the most important programming tool. In Python it s easy: for i in range(n): means repeat this code n times. We re repeating forward(100) and left(90) four times, so we can save some typing by using a loop like this:

Notice the code we want to repeat is indented. This is extremely important, since that s how Python knows which lines you want to repeat! If you don t indent a line of code, it won t be repeated, like this example: Since dippity is indented it gets repeated 3 times but doo isn t indented, so it s only printed once. Functions Now that we have all the code necessary to draw a square, let s save all that code to a function. This means that we ll be able to use the function name, like a magic word, in the future instead of typing all the code all over again. In Python you define a function by coming up with a name (I m going with the descriptive name square ) and you tell Python it s a function with the abbreviation def in front of it: Notice all the code inside the square function has to be indented (again if it s already indented!). If you run the program now, it won t draw anything. You ve told the turtle how to draw a square, but you didn t tell it to. Add the last line so the square function executes automatically when you run the program.

The Rosette Now that we ve taught the turtle to make a square, and saved it to the magic word/function square, next we ll tell it to square, then turn left a little, square again, turn left a little, over and over. Sounds like a job for a loop! Change your code to this: When you click Run, you should see a rosette like this: This shows that when you repeat things a lot of times using loops, you can make surprisingly complicated designs with very little code! The Spiral

But our squares are all the same size. What if we wanted to make them different sizes? What would we have to change? Only the forward line. Whatever size we want the square to be (its side length) we just put in the parentheses after the forward command. square(10) will make a square of side length 10 for example. Now you can use a variable to make squares of any size! Add the spiral code below: But when you press Run, nothing happens! Remember, you have to tell the turtle to run the spiral function by adding this line at the very end of the program: Click Run and the turtle will draw a growing, expanding spiral of squares.

You can easily change the base shape to a circle, a triangle or a star. This is a very useful procedure: making parts of your program into a variable (like we did with length) so we can vary it! Have fun making more designs using Python!