Advertisement
HBSB

1.8 Funcs w parameters

Apr 5th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. from turtle import Turtle
  2.  
  3. tina = Turtle()
  4.  
  5. # we originally had a line tina.dot(100) which resulted in the program drawing
  6. # a black circle with a diameter of 100.
  7.  
  8. # This has been deleted now that the following code has been added.
  9. # The new code is to have us make the radius: as a function with the radius as
  10. # a parameter of the function.
  11.  
  12. def draw_circle(Tina,r,red):
  13.   tina.color(red)
  14.   tina.dot(r*2)
  15. draw_circle(tina,25,"red")
  16.  
  17. # then we can add colour (american spelling, so color) by including it in
  18. # the definition of draw_circle, so
  19.  
  20. # so we will go back and add color as a parameter inside the draw_circle()
  21. # below the def line we add tina.color(colorchoice)
  22.  
  23. # finally we give our instr5uvction (see line 14) to which we have added "red"
  24.  
  25. # IT WORKS
  26.  
  27. # AND NOW to create coloured circles, code would look like
  28.  
  29. draw_circle(tina,100,"blue")
  30. draw_circle(tina,60,"white")
  31. draw_circle(tina,20,"red")
  32.  
  33. # THAT WORKS TOO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement