How to the def command
How do you do the def command that makes it repeat code and can make slight differences in python coding?
The def is basically a function. So it defines what you are writing. Like this:
def printhi(): return "hi" # in functions, good practice would be to use return printhi() # here you call it
Like that, functions are useful,instead of repeating code, you use the function name. you can learn more here:
A good example of this would be something like:
def greet(person): print("Hello %s!" % (person)) greet("Coder100") greet("Taiga") greet("someone else")
it will save you from a lot of typing!
This is my code but I forgot how to define the varible also what does import random do???
import random Afk2 = turtle.Turtle() Afk2.speed(18) def repeat(Afk2Code): print(Afk2) + (Afk2Code)) Afk2.color('white') Afk2.forward(168) Afk2.left(90) Afk2.pencolor('cyan') Afk2.begin_fill() Afk2.color('red') Afk2.circle(100,180) Afk2.end_fill() Afk2.left(90) Afk2.pendown() Afk2.forward(100)