Ask coding questions

← Back to all posts
Python(with turtle) questions.
Taiga123m (3)

I cant fill and can somebody give me a example.
Also what does import random do? Also the def command and how do you make it repeat?

Answered by RYANTADIPARTHI (6018) [earned 5 cycles]
View Answer
Comments
hotnewtop
RYANTADIPARTHI (6018)

Solutions to everything:

Fill

In fill, there are two commands: begin_fill() and end_fill(), the begin_fill() is at the beginning, and starts the filling in your turtle shape. The end_fill() ends it. Here's an example:

import turtle

turtle = turtle.Turtle()
turtle.shape("classic")
turtle.color("red")

begin_fill("red")
for i in range(4):
  turtle.forward(100)
  turtle.left(90)
end_fill()

So that makes a square, since it repeats for 4 times. And fills the color in the shape with the commands.

Random module

The random module is a very useful module in python, that gets the random of something. there is a choice or randint any of them can be used. it think there are more, but these are useful for now. Example:

  • random.choice()
import random

stuff = ["1", '2', '3', '4']
random = random.choice(stuff)
print(random)

So that gets random stuff from the list. You can use it any list, or something.

  • random.randint
from random import randint

random = random.randint(1, 10)
print(random)

So that gets the random of 10 numbers. You can change it. So use either of them.

def command

The def is a command. It is a function, which is basically something that can be used and called instead of using the code over, and over. Just call it.

def something():
  return "hi"
something()

So now, if you don't want to print out hi all the time, just call the function like this:

something()

Like that, now that will just call the hi instead of writing again.

Here are a few tutorials:
https://docs.python.org/3/tutorial/
https://www.learnpython.org/

If you have any questions, just ping me.

Taiga123m (3)

@RYANTADIPARTHI uhhhhh I copied the code for the fill command but its says "begin_fill is not defined"

RYANTADIPARTHI (6018)

@Taiga123m sorry, try this code:

import turtle

turtle = turtle.Turtle()
turtle.shape("classic")
turtle.color("red")

t.begin_fill()
for i in range(4):
  turtle.forward(100)
  turtle.left(90)
t.end_fill()
Taiga123m (3)

@RYANTADIPARTHI when I changed turtle to t it did work but it didnt fill

RYANTADIPARTHI (6018)

@Taiga123m oop, sorry, it should be turtle instead of .t. It should be turtle.begin_fill() and turtle.end_fill()

Taiga123m (3)

Also why do you need
for i in range(4): for the code???

RYANTADIPARTHI (6018)

@Taiga123m you don't have to. it makes a square. the 4 just loops over it, to go 4 times.

Taiga123m (3)

@RYANTADIPARTHI what does your quote mean in ur bio?

RYANTADIPARTHI (6018)

@Taiga123m just a joke, i made it on my own.

Taiga123m (3)

@RYANTADIPARTHI that makes much more sense

Taiga123m (3)

@RYANTADIPARTHI help I can't comment properly
it says it "can't find the comment" what the heck :CCC

Taiga123m (3)

@RYANTADIPARTHI Its not working I fixed the def command

import random
Afk2 = turtle.Turtle()
Afk2.speed(18)
def repeat(Afk2Code):
print(Afk2.) + (2Afk2Code))
return forward(20)
2Afk2Code())

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)
Taiga123m (3)

@RYANTADIPARTHI I fixed the def code but it won't work

import random
Afk2 = turtle.Turtle()
Afk2.speed(18)
def repeat(Afk2Code):
print(Afk2.) + (2Afk2Code))
return forward(20)
2Afk2Code())

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)
RYANTADIPARTHI (6018)

@Taiga123m uh, what's your question. can you ask this separately? Like make a post? It will be much better.

Taiga123m (3)

@RYANTADIPARTHI Hey I fixed with the def command but it won't print the turtle drawings import turtle
import random
Afk2 = turtle.Turtle()`
Afk2.speed(18)
def repeat(Afk2Code):
print(Afk2.) + (2Afk2Code))
return forward(20)
2Afk2Code())

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)

Taiga123m (3)

@RYANTADIPARTHI okay sorry its like broken

Taiga123m (3)

@RYANTADIPARTHI I can't comment properly and repl.it goes crazy every time I comment

RYANTADIPARTHI (6018)

@Taiga123m yeah, once you ask it somewhere, i'll help.

Taiga123m (3)

Also executing specific group of code

Taiga123m (3)

@Baconman321 sorry I couldn't find your comment and I have ask again sorry. I'm sorry I cant find it.

Baconman321 (1097)

@Taiga123m What do you want? And what comment?

Baconman321 (1097)

@Taiga123m it's emjohansson. Anyways, they gotta have private messaging on repl... :/

Coder100 (18149)

Anyways, the import random will import some commands for you to generate random numbers, and the def syntax allows you to define 'functions' which allow you to repeat code without having to type code over and over again.

Taiga123m (3)

@Coder100 thx but with actual people its easier for me at least

Taiga123m (3)

@Coder100 dude YOU ACTUALLY HAVE over 10,000 UPVOTES??????!???!?!?!??1?!//1