-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogics.py
149 lines (109 loc) · 2.72 KB
/
logics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
Solve this fun exercise(challenge 25)
# This program is supposed to draw the Cyrillic letter Ц ('tse'), but something went wrong. Can you figure out which line needs to be changed?
from turtle import *
width(5) # make the stroke 5 pixels wide
left(90) # option A
forward(200)
left(90) # option B
forward(150)
left(90)
forward(200)
left(180) # option C
forward(200)
left(90)
forward(30)
right(90) # option D
forward(30)
hideturtle() # hide the turtle from the final image
bye()
# The code underneath is fixed to the correct way
width(5) # make the stroke 5 pixels wide
right(90) # option A
forward(200)
left(90) # option B
forward(150)
left(90)
forward(200)
left(180) # option C
forward(200)
left(90)
forward(30)
right(90) # option D
forward(30)
hideturtle() # hide the turtle from the final image
bye()
# Another exercise to draw a letter C
# Sovle this quest(challenge 26)
# This program attempts to draw the letter C, but the turning angle needs to be adjusted:
from turtle import *
width(5)
left(180) # Orients the Turtle left
forward(50)
left(50) # Turning angle
forward(50)
left(40) # Turning angle
forward(50)
left(40) # Turning angle
forward(50)
left(50) # Turning angle
forward(50)
hideturtle()
bye()
# Similar challenge to the above but different approach(Using for loop)
# Challenge 27
# Here's a more compact version of the previous program that uses a for loop. Read the program's comments, and then run it:
from turtle import *
width(5)
left(180)
# Start of for loop.
for i in range(5): # Code below is repeated 5 times
# Code to be repeated
forward(50) # Indentation indicates code is inside the loop
left(45) # Still inside the for loop
# No more indentation! Marks the end of the for-loop.
hideturtle()
bye()
# Try this program and see the shorthand for it
forward(100)
left(45)
forward(100)
left(45)
forward(100)
left(45)
forward(100)
left(45)
forward(100)
left(45)
#
# Here is the shorthand for similar program using the (for loop)
for i in range(5):
forward(100)
left(45)
# This is more easier, readable and professional way for writting complex programs
Lets try this out (challenge 28)
from turtle import *
width(5)
left(180) # Orient the Turtle
for i in range(5):
forward(50)
left(45) # Turning angle
hideturtle()
bye()
# Lets draw a letter 0 or o using for loop(challenge 29)
from turtle import *
width(5)
left(180)
for i in range(36): # Adjusted to draw a circle
forward(10) # Reduced the forward distance
left(10) # Adjusted the angle for smoother curves
hideturtle()
bye()
# A similar approach here(They both works)
from turtle import *
width(5)
left(180)
for i in range(8):
forward(50)
left(45)
hideturtle()
bye()