L 36 [L 4 [F 100 R 90] R 10]
Explanation : This program first loop 36 times inside the closed paranthesis and inside 4 times draw F 100 and R 90 (basic square draw) then right 10 degrees and draw square again.
I have project so I want to do functions like this but my code does not working.I add F and R functions as an argument to L function but I cant add L function as an argument to L function.How can I solve this?
from turtle import Turtle,Screen
s = Screen() t = Turtle()
def F(value):
t.forward(value)
def R(value):
t.right(value)
def L(value1, *args, **kw):
for i in range(value1):
for func in args:
func(kw[func.__name__])
for i in range(36):
L(4, F, R, F=100, R=90)
L(1, R, R=10)
I can do like this and work but I cant in one function.
s.exitonclick()
Try defining all of your functions as methods inside a class
for i in range(36)... should be a method as well.
If 36 is a constant, leave it as is. If it's a var, define it as such for the class.
You could go even further with @property decorators, so you can access the last function as an class atribute.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.