[Python] O funcție pentru un pătrat - Python - GAMELIFE România Jump to content

Recommended Posts

Posted

python-3.svg

 

O funcție pentru un pătrat

 

Exercițiu

Scrie o funție care desenează un pătrat. Poți utiliza această funcție pentru a îmbunătăți programul cu pătrate înclinate? Dacă schimbi programul pentru a folosi o funcție, este mai ușor să experimtentezi?

Soluție

def tilted_square():
  turtle.left(20)     # now we can change the angle only here
  for _ in range(4):
      turtle.forward(50)
      turtle.left(90)

tilted_square()
tilted_square()
tilted_square()

# bonus: you could have a separate function for drawing a square,
# which might be useful later:

def square():
  for _ in range(4):
      turtle.forward(50)
      turtle.left(90)

def tilted_square():
  turtle.left(20)
  square()

# etc

 

76561198361326087.png

TS3 SERVER : 193.84.64.140:10017

174855.png  facebook-new.png

#statiincasa

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...

Important Information