Previous Lecture Complete and continue  

  Lesson 7: Functions with Multiple Arguments

53 comments
Hannah Nyarkoah Nyarko
https://repl.it/GB9T/1
Hannah Nyarkoah Nyarko
https://repl.it/GB9T/1
Hannah Nyarkoah Nyarko
https://repl.it/GB9T/1
Marek Ondrejka
import turtle

t = turtle.Turtle()

def triangle(lenght, angle):
t.forward(lenght)
t.left(angle)
t.forward(lenght)
t.left(angle)
t.forward(lenght)

triangle(150, 120)
MEHMET
import turtle

import turtle


my_turtle = turtle.Turtle()
my_turtle.pencolor("red")


def kare(length, angle):
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)





kare(50, 40)
kare(60, 50)

Göran Premberg
How come I get this message when coding excatly according to the course?
"NameError: name 'length' is not defined on line 15 in main.py"

import turtle

my_turtle = turtle.Turtle()

def square(lenght):
my_turtle.forward(length)
my_turtle.right(90)
my_turtle.forward(length)
my_turtle.right(90)
my_turtle.forward(length)
my_turtle.right(90)
my_turtle.forward(length)
my_turtle.right(90

square(50)
Emran Bhuiyan
import turtle

my_turtle = turtle.Turtle()

def square(length): [you misspelled the length]

my_turtle.forward(length) [you have to press tab here, the whole my_turtle
my_turtle.right(90)
my_turtle.forward(length)
my_turtle.right(90)
my_turtle.forward(length)
my_turtle.right(90)
my_turtle.forward(length)
my_turtle.right(90) [you forget to put close parentheses]

square(50)
VIREN PATEL
import turtle
my_turtle = turtle.Turtle()


def square(l,a):
my_turtle.forward(l)
my_turtle.right(a)
my_turtle.forward(l)
my_turtle.right(a)
my_turtle.forward(l)
my_turtle.right(a)
my_turtle.forward(l)
my_turtle.right(a)


square(250,90)
square(200,90)
square(150,90)
square(100,90)
square(50,90)
square(25,90)
square(10,90)
Paul Ojong
Can you help me with this code the turtle won't move import turtle
my_turtle = turtle.Turtle()


def square(length,angle):





my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)


square(length, angle)
Charlie Cox
You didn't assign the variables (length, angle) to a value.
Alex Koo
import turtle

my_turtle = turtle.Turtle()

def square(length, angle):
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)

square(20,90)


Ok so I edited your language. You had to put space in between (length,angle) and you had typos and thats why it didnt work for you
Paul Ojong
Thank you very much!
Fedor Vasilyev
When you call out square, you need to set the lengh and angle in the last line square(length, angle)
Charlie Cox
import turtle

t = turtle.Turtle()

f = 200
a = 90

def square(f, a):
t.forward(f)
t.left(a)
t.forward(f)
t.left(a)
t.forward(f)
t.left(a)
t.forward(f)

square(f, a)
Alex Koo
import turtle

my_turtle = turtle.Turtle()
my_turtle.speed(50)
#defining a function, square, to create a square
def square():
my_turtle.forward(100)
my_turtle.right(90)
my_turtle.forward(100)
my_turtle.right(90)
my_turtle.forward(100)
my_turtle.right(90)
my_turtle.forward(100)

#in order for this to work, you need to call out function, square.
square()

#if you want to make another square, simply call out the function again
my_turtle.forward(100)
square()
my_turtle.left(90)
my_turtle.forward(25)
my_turtle.left(90)
my_turtle.forward(600)
my_turtle.right(90)
my_turtle.forward(50)
my_turtle.right(90)
my_turtle.forward(600)
Michael Daniels
import turtle

my_turtle = turtle.Turtle()

#give the function, square, context
def square(length, angle):

my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)

#now, plug in numbers for length and direction inside function to give it context
square(100,45)
#this draws an octagon.

Arshad
Greetings,
We reading an article and it said that Pyton 3 is not good to learn. If you want to learn learn Python 2.
How true is that?
Thank you.
Rafeh Qazi
Not true at all!
Luftwafte II
Amen to that bro
Rafeh Qazi
Not true at all. The only thing is that more tutorials cover Python 2 because it has been out longer than Python 3. However, everyone is switching to Python 3 now so it is better to think about the future and learn Python 3. Also, there are only a few basic differences for beginners.

Python 2
print 'banana'


Python 3
print('banana')


Not putting parenthesis after print is what throws many beginners off.
Ze At
the python which i installed on my windows does not enable editting
hanny-awamleh
yeah me to
Luftwafte II
You have to run it without the IDLE
Luftwafte II
Run this piece of code
import turtle

my_turtle = turtle.Turtle()

def square(l,h):
for n in range(4):
my_turtle.forward(l)
my_turtle.left(h)
my_turtle.forward(l)
my_turtle.left(h)
my_turtle.forward(l)
my_turtle.right(h)


#We're calling the square function
square(100,90)
Dean Roberts
import turtle
my_turtle = turtle.Turtle()




#makes sqare
def sqare(length,angle):
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)

#how big the sqare is
sqare(50,30)
sqare(20,30)
sqare(20,30)
sqare(20,30)
sqare(20,30)
Luftwafte II
Use repl.it :)
brian reaume
I have to say I was I was pretty skeptical of the pitch of fun and easy. But I am rather impressed with the course. only 7 lessons in. I have very limited coding experience. But I am pretty happy with the limited lines of code.I really focused on using loops and functions as much I a could. Looking forward to moving forward.

import turtle
import time
my_turtle = turtle.Turtle()

my_turtle.pensize(2)
my_turtle.penup()
my_turtle.goto(-175, 175)
my_turtle.pendown()

def house(color):
my_turtle.pencolor(color)
for i in range(3):
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)
my_turtle.left(135)
my_turtle.forward(142)
for i in range(2):
my_turtle.left(90)
my_turtle.forward(71)
my_turtle.left(90)
my_turtle.forward(142)
time.sleep(.350)

def Draw():
my_turtle.penup()
my_turtle.left(45)
my_turtle.forward(20)
my_turtle.pendown()

def inner(color,L1,L2,A1,A2,A3):
my_turtle.penup()
my_turtle.goto(-173, 173)
my_turtle.pendown()
my_turtle.pencolor(color)
for i in range(4):
my_turtle.forward(L2)
my_turtle.right(A2)
my_turtle.right(A1)
my_turtle.forward(L1)
my_turtle.right(A3)
my_turtle.penup()
my_turtle.goto(-173, -164)
my_turtle.pendown()
my_turtle.right(A3)
my_turtle.forward(L1)

#Draw Houses
for i in range(4):
house("green")
Draw()
house("blue")
Draw()
house("red")
my_turtle.right(45)

inner ("purple", 479, 337, 45, 90, 135)

#Erase Houses
my_turtle.penup()
my_turtle.goto(-175, 175)
my_turtle.pendown()
my_turtle.right(45)

for i in range(4):
house("white")
Draw()
house("white")
Draw()
house("white")
my_turtle.right(45)

inner ("White", 477, 337, 45, 90, 135)
Kevin C
import turtle
my_turtle = turtle.Turtle()
def square(length,angle):
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(157)
my_turtle.forward(110)
square(100,135)
print("I got mad skills")
Robert de los santos
import turtle

def square():

my_turtle = turtle.Turtle()
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)

square()
my_turtle.forward(100)

RESTART: C:/Users/USGOV/AppData/Local/Programs/Python/Python36-32/animal.py
Traceback (most recent call last):
File "C:/Users/USGOV/AppData/Local/Programs/Python/Python36-32/animal.py", line 15, in
my_turtle.forward(100)
NameError: name 'my_turtle' is not define

notes please look at this one the other one was not in detail
thanks robert
Saad Ahmad Khan
#define variable outside of the funcation body.
my_turtle = turtle.Turtle()
def square():

Saad Ahmad Khan
import turtle

my_turtle = turtle.Turtle()

my_turtle.speed(10)
def my_square(length,angle):
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)


my_square(50,90)
rahul raj mishra
see this

https://repl.it/FXiR/1

thanks
V
import turtle

my_turtle = turtle.Turtle()

def square():
my_turtle = turtle.forward(100)
my_turtle = turtle.left(90)
my_turtle = turtle.forward(100)
my_turtle = turtle.left(90)
my_turtle = turtle.forward(100)
my_turtle = turtle.left(90)
my_turtle = turtle.forward(100)

square()

lol = square()

lol
Jesudara Omidokun
import turtle

my_turtle = turtle.Turtle()
def octagon(lenght,angle):
n = lenght
a = angle
my_turtle.forward(n)
my_turtle.left(a)
my_turtle.forward(n)
my_turtle.left(a)
my_turtle.forward(n)
my_turtle.left(a)
my_turtle.forward(n)
my_turtle.left(a)
my_turtle.forward(n)
my_turtle.left(a)
my_turtle.forward(n)
my_turtle.left(a)
my_turtle.forward(n)
my_turtle.left(a)
my_turtle.forward(n)



octagon(100,45)
Mario
https://repl.it/FR8G/1

ready for more i even made a "option menu" so you can change setting easily
poonam ahir
import turtle
hi = turtle.Turtle()

def polygon(length, angle):
hi.forward(length)
hi.left(angle)
hi.forward(length)
hi.left(angle)
hi.forward(length)
hi.left(angle)
hi.forward(length)
hi.left(angle)
hi.forward(length)

polygon(50,75)
wenting zhang
https://repl.it/FNny/0
PaRuSch
Went a little bit more fancy with all the stuff I learned till now. Go copy and test it yourself ^-^
https://repl.it/FKuw/0
Praneeth
import turtle
a = turtle.Turtle()
def polygon(length , angle):
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)

polygon(25 , 90)
a.forward(100)
polygon(25 , 45)

Edmundo Aguirre
import turtle

my_turtle = turtle.Turtle()

def square(length,angle):


my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)

square(100,45)
#square(150)
#square(50)
shane
import turtle
my_turtle = turtle . Turtle()
def square(length, angle):


my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)



square(100,90,)
Abdulla Omaruddin
import turtle
def square (length, angle):
my_turtle = turtle.Turtle ()
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)
my_turtle.forward (length)
my_turtle.left (angle)

square (100, 60)
Anidhito Irmandharu
import turtle

Avant = turtle.Turtle()

def square(xlength ,turn):
Avant.forward(xlength)
Avant.right(turn)
Avant.forward(xlength)
Avant.right(turn)
Avant.forward(xlength)
Avant.right(turn)
Avant.forward(xlength)

# This is A Single
# Flower Petal

square(200 ,90)
Avant.right(120)
square(150 ,90)
Avant.right(120)

#-----------------

square(200 ,90)
Avant.right(120)
square(150 ,90)
Avant.right(120)

square(200 ,90)
Avant.right(120)
square(150 ,90)
Avant.right(120)

square(200 ,90)
Avant.right(120)
square(150 ,90)
Avant.right(120)

square(200 ,90)
Avant.right(120)
square(150 ,90)
Avant.right(120)

square(200 ,90)
Avant.right(120)
square(150 ,90)
Avant.right(120)


it look like a flower to be honest heheh
kenneth
the shape not quiet nice
try this

import turtle

squareCircle=turtle.Turtle()
squareCircle.speed(250)
def circles(length,angle,new):
squareCircle.forward(length)
squareCircle.right(angle)
squareCircle.forward(length)
squareCircle.right(angle)
squareCircle.forward(length)
squareCircle.right(angle)
squareCircle.forward(length)
squareCircle.right(new)
squareCircle.pencolor("green")
for i in range(25):
circles(90,90,104.5)



import turtle
squareCircle=turtle.Turtle()
squareCircle.speed(250)
def circles(length,angle,angles,new):
squareCircle.forward(length)
squareCircle.right(angle)
squareCircle.forward(length)
squareCircle.right(angles)
squareCircle.forward(length)
squareCircle.left(angle)
squareCircle.forward(length)
squareCircle.right(new)
squareCircle.pencolor("blue")
for i in range(25):
circles(90,90,180,194.5)
kenneth
import turtle
flag=turtle.Turtle()
flag.speed(250)

#forming the borders

flag.pensize(2)
flag.color("black")
flag.setposition(0, 0)
flag.left(90)
flag.forward(140)
flag.right(90)
flag.forward(250)
flag.right(90)
flag.forward(260)
flag.right(90)
flag.forward(400)
flag.right(90)
flag.forward(260)
flag.right(90)
flag.forward(150)
flag.right(90)
flag.forward(140)
flag.right(90)
flag.forward(150)
flag.right(180)
flag.penup()

#function to generate red rectangles and blue block
def part(long,width,angle):
flag.pendown()
flag.begin_fill()
flag.forward(long)
flag.right(angle)
flag.forward(width)
flag.right(angle)
flag.forward(long)
flag.right(angle)
flag.forward(width)
flag.end_fill()
flag.right(angle)
flag.penup()
flag.setposition(-150,140)
flag.color("blue")
part(150,140,90)
y=140
while(y>0):
x=2
flag.setposition(2,y)
flag.color("red")
part(248,20,90)
y -=40
y= -20
while(y>-110):
x=2
flag.setposition(-150,y)
flag.color("red")
part(400,20,90)
y -=40

#function to generate each star

def star(length,left,right):
flag.right(right)
flag.forward(length)
flag.left(left)
flag.forward(length)

# function to generate row of stars

def draw_rowofstars():
y=124
while(y>10):
x= -130
for n in range(7):
flag.setposition(x,y)
flag.pensize(1)
flag.pendown()
flag.begin_fill()
flag.color("white")
for i in range(5):
star(5,72,144)
flag.end_fill()
flag.penup()
x +=20
y -= 22

draw_rowofstars()
flag.hideturtle()
This comment has been removed
Mousa Tams
I Like your Style
Rafeh Qazi
haha you guys!!
Jordan
Smooth my man, Smooth XD
Jasper Oh
import turtle
jasper=turtle.Turtle()
jasper.speed(100)
def square(lenght,angle):
for i in range(4):
jasper.forward(lenght)
jasper.left(angle)
square(50,90)
Diwaker Thakur
import turtle
my_turtle = turtle.Turtle()

def tringle(length, angle):
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
tringle(100, 60)
Anthony Davis
https://repl.it/EvOS/3
Robert Spina
import turtle

my_turtle = turtle.Turtle()
def square(length, angle):
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)



square(60, 120)
my_turtle.forward(10)
square(50, 120)
my_turtle.forward(10)
square(60, 120)
my_turtle.forward(10)