more coding basics with some turtle · announcement homework 2 will be posted this thursday. due...
TRANSCRIPT
![Page 1: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/1.jpg)
More Coding Basics
with Some Turtle
![Page 2: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/2.jpg)
Announcement
� Homework 2 will be posted this Thursday. Due dates will be adjusted. � Missing quiz policy: no quiz submissions will be accepted late, except
in the case of a documented medical emergency.� Since we drop a quiz grade, there is NO make-up quiz unless there is
a medical emergency.� If you have situations where you suspect you will miss the quiz
regularly (e.g. military service), please discuss with the instructor via writing, supporting documents are required.
� If you do miss a quiz, you will have other opportunities to earn points throughout the class
![Page 3: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/3.jpg)
Learn to program = Learn to solve problems
![Page 4: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/4.jpg)
Python
More Coding Basics
Credit: lecture notes modeled after http://www.openbookproject.net/thinkcs/python/english2e/index.html
![Page 5: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/5.jpg)
What is a function?
![Page 6: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/6.jpg)
Def FUNCTIONNAME(parameters):____STATEMENTS
Syntax
Indentation (4 empty spaces)
header
body
![Page 7: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/7.jpg)
User-defined Functions
![Page 8: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/8.jpg)
def new_line(): print print "The weirdest movie at Sundance this year is:"new_line()print "Swiss Army Man."
![Page 9: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/9.jpg)
The weirdest movie at Sundance this year is:
Swiss Army Man.
![Page 10: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/10.jpg)
def new_line(): print print "The weirdest movie at Sundance this year is:"new_line()new_line()print "Swiss Army Man."
![Page 11: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/11.jpg)
The weirdest movie at Sundance this year is:
Swiss Army Man.
![Page 12: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/12.jpg)
print ' * 'print ' *** 'print ' ***** 'print '*******'for h in range(0,5): print '| |'print '-------'
![Page 13: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/13.jpg)
![Page 14: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/14.jpg)
def print_house(height): print ' * ' print ' *** ' print ' ***** ' print '*******' for h in range(0,height): print '| |' print '-------'print_house(2)
![Page 15: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/15.jpg)
http://www.pythontutor.com/index.html
![Page 16: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/16.jpg)
A Function can be called repeatedly.Function can call another function.
![Page 17: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/17.jpg)
def new_line(): print def print_house(height): print ' * ' print ' *** ' print ' ***** ' print '*******' for h in range(0,height): print '| |' new_line() print '-------'print_house(2)
![Page 18: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/18.jpg)
![Page 19: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/19.jpg)
Advantages of using a function:� Group complex computations� Smaller code for repetitive ops
![Page 20: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/20.jpg)
Flow of Executionhttp://www.pythontutor.com/index.htmlForward bottom will show step by step execution of the program
![Page 21: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/21.jpg)
Build-in Functions
![Page 22: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/22.jpg)
https://docs.python.org/2/library/functions.html
![Page 23: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/23.jpg)
print abs(5)print abs(-5)print pow(2,3)print max(2,3,8,1)
![Page 24: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/24.jpg)
5588
![Page 25: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/25.jpg)
Functions can be composed.
![Page 26: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/26.jpg)
print abs(max(-1,-2,-5))print max(abs(-1),abs(-2),abs(-5))
![Page 27: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/27.jpg)
15
![Page 28: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/28.jpg)
Local variables are only defined inside the function.
![Page 29: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/29.jpg)
def print_house(height): print ' * ' print ' *** ' print ' ***** ' print '*******' for h in range(0,height): print '| |' print '-------' print type(height)print_house(2)
![Page 30: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/30.jpg)
def print_house(height): print ' * ' print ' *** ' print ' ***** ' print '*******' for h in range(0,height): print '| |' print '-------'print_house(2)print type(height)
![Page 31: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/31.jpg)
Modulus operator: %
![Page 32: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/32.jpg)
remainder = 11%2print remainderright_most_digit = 123%10print right_most_digit
![Page 33: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/33.jpg)
13
![Page 34: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/34.jpg)
Conditionals
![Page 35: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/35.jpg)
Boolean Values and ExpressionsTrue, False
==, !=, >=, <=, >, <
![Page 36: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/36.jpg)
print type(True)print 5==5print 4==5
![Page 37: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/37.jpg)
<type 'bool'>TrueFalse
![Page 38: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/38.jpg)
x=4y=5print x!=yprint x>yprint x<yprint x>=yprint x<=y
![Page 39: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/39.jpg)
TrueFalseTrueFalseTrue
![Page 40: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/40.jpg)
Boolean Values and Expressions
![Page 41: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/41.jpg)
x=4y=5print (x!=y) and (x>y)print (x!=y) or (x>=y)print not(x==y)
![Page 42: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/42.jpg)
FalseTrueTrue
![Page 43: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/43.jpg)
If Statement
![Page 44: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/44.jpg)
IF BOOLEAN EXPRESSION:____STATEMENTS
Syntax
Indentation (4 empty spaces)
header
body
![Page 45: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/45.jpg)
x = 4if x>0: print "x is positive."
![Page 46: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/46.jpg)
TrumpIsPresident = Trueif TrumpIsPresident print "What would you do?"
![Page 47: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/47.jpg)
if BOOLEAN EXPRESSION:____STATEMENTSelse:____STATEMENTS
Syntax
![Page 48: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/48.jpg)
x = -4if x>0: print "x is positive." else: print "x is not positive."
![Page 49: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/49.jpg)
x = 4if x%2==0: print x, "is even." else: print x, "is odd."
![Page 50: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/50.jpg)
if TrumpBecomesPresident print "The republicans win." else print “The democrats might win.”
![Page 51: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/51.jpg)
if BOOLEAN EXPRESSION:____STATEMENTSelif BOOLEAN EXPRESSION:____STATEMENTSelse:____STATEMENTS
Syntax: Chained Conditionals
![Page 52: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/52.jpg)
x = 0if x>0: print "x is positive." elif x<0: print "x is negative."else: print "x is zero."
![Page 53: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/53.jpg)
Nested Conditionals
![Page 54: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/54.jpg)
x = 2y = 3if x==y: print x," equals ", yelse: if x<y: print x, " less than ", y else: print x, " is bigger than ", y
![Page 55: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/55.jpg)
TrumpBecomsePresident=FalseHillaryBecomesPresident=Falseif TrumpBecomsePresident: print "The republicans win." else: if HillaryBecomesPresident: print "The Democrats win." else: print "Some independent wins."
![Page 56: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/56.jpg)
Return Statement
![Page 57: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/57.jpg)
Terminates the execution of a function before it reaches the end
![Page 58: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/58.jpg)
def print_square_root(x): if x <= 0: print "Invalid input." return
result = x**0.5 print "The square root of", x, "is", resultprint_square_root(-8)
![Page 59: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/59.jpg)
Type Conversion
![Page 60: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/60.jpg)
print int("123")print int(1.25)print float(2.5)print float("2.6")print str("12345")
![Page 61: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/61.jpg)
Function that Returns
![Page 62: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/62.jpg)
def absolute_value(x): if x < 0: return -x else: return xprint absolute_value(-5)
http://www.pythontutor.com/index.html
![Page 63: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/63.jpg)
For Loop
![Page 64: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/64.jpg)
for iterating_var in sequence:____STATEMENTS
Syntax
![Page 65: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/65.jpg)
Python Turtle
![Page 66: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/66.jpg)
import turtlejohnny = turtle.Turtle()for i in range(0,4): johnny.forward(100) johnny.right(90)
https://trinket.io/python
![Page 67: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/67.jpg)
import turtlejohnny = turtle.Turtle()for i in range(0,4): johnny.forward(100) johnny.right(90)
![Page 68: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/68.jpg)
import turtledef run_in_square(x,y): johnny = turtle.Turtle() johnny.hideturtle() johnny.setpos(x, y) print johnny.position() for i in range(0,4): johnny.forward(10) johnny.right(90)run_in_square(10,10)run_in_square(20,20)for i in range(1,5): run_in_square(i*10,i*10)
![Page 69: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/69.jpg)
import turtledef draw_polygon(sides, length):
johnny = turtle.Turtle() for i in range(0,sides): johnny.forward(length) johnny.right(360/sides)
draw_polygon(4,20)
draw_polygon(6,20)
Credit: https://www.linuxvoice.com/issues/002/02drawing.pdf
![Page 70: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/70.jpg)
import turtledef draw_spiral(angle, length_start, length_increase, sides): for i in range(0,sides): johnny.forward(length_start+(i*length_increase)) johnny.right(angle)
johnny = turtle.Turtle() draw_spiral(30, 10, 2, 20)
Credit: https://www.linuxvoice.com/issues/002/02drawing.pdf
![Page 71: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/71.jpg)
Play with Python
labs on your own!
![Page 72: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/72.jpg)
thanks!
Any questions?
You can find me [email protected]
http://www.sci.utah.edu/~beiwang/teaching/cs1060.html
![Page 73: More Coding Basics with Some Turtle · Announcement Homework 2 will be posted this Thursday. Due dates will be adjusted. Missing quiz policy: no quiz submissions will be accepted](https://reader033.vdocuments.site/reader033/viewer/2022060315/5f0be0ea7e708231d432a989/html5/thumbnails/73.jpg)
Credits
Special thanks to all the people who made and released these awesome resources for free:� Presentation template by SlidesCarnival� Photographs by Unsplash