Skip to playerSkip to main contentSkip to footer
  • 5/20/2025
Drawing shapes like triangles in Python typically involves using graphics libraries such as turtle or matplotlib. These libraries provide functions to control drawing elements on a canvas. The turtle library is particularly beginner-friendly, as it simulates a turtle moving and drawing lines based on commands.

Category

📚
Learning
Transcript
00:00We have time for a exercise.
00:02We have to draw a rectangle.
00:06Now you can pause the video and attempt it.
00:10Otherwise, we are going to solve this problem.
00:13First of all, we will print the top of the line and bottom of the line.
00:21This is very easy.
00:22Imagine that I will define a variable.
00:25Let's say, I will say canvas.
00:28Canvass value is 10.
00:30Now I can print 10 times using canvas.
00:37For example, I will say print.
00:41I will say print.
00:43Let's say x.
00:45I will multiply by canvas times.
00:49This is my region where I have to print.
00:51Now I will execute the top of the line.
00:55Then I will do the bottom line.
00:58Then I will do the bottom line.
01:00There will be two lines.
01:02Basically, I will do the first position and the last position.
01:08Print.
01:09Then I will use a print.
01:11Then I will use the first position.
01:13I will use the first position.
01:16Then string concatenation.
01:18And space is empty.
01:20But how many times do space is empty?
01:22Canvass times?
01:23Maybe not.
01:24The reason is that if canvas time space is empty.
01:28Like I will show you.
01:30Canvass times plus the final mark.
01:34The final mark.
01:35x.
01:36Okay.
01:37And execute.
01:39As you see,
01:41As you see,
01:42کیونکہ ہمارے پاس
01:43یہ جو line ہے
01:44یہ آگے نکل گئی ہے.
01:46Toh ہم اس طرح کرتے ہیں
01:47کہ اگر میں اس کو minus two کرتا ہوں
01:49اور execute کرتا ہوں.
01:51Now we will see
01:53this variable c
01:54جو ہمارا square ہے
01:55اس کی
01:56جو
01:57dimension ہے
01:58وہ ٹھیک ہو جائے گی.
02:00However
02:01اگر آپ یہاں پہ غور کریں
02:03کہ یہاں پہ جو
02:04کیونکہ ہم string concatenation
02:06کر رہے ہیں
02:07arithmetic operation
02:08نہیں کر رہے
02:09تو اس لئے یہ ہمیں
02:10error دے رہا ہے.
02:11تو اس کو ہمیں
02:12کوئی اور variable میں
02:13save کرنا پڑے گا
02:14تو یہاں پہ میں آتا ہوں
02:15اور اس کو کہتا ہوں
02:16یہ ہے
02:17inner
02:18underscore
02:19area
02:20that is canvas minus two
02:22تو اب بجائے arithmetic operation
02:24string concatenation میں
02:25کرنے کے
02:26میں یہاں پہ
02:27inner area replace کر دیتا ہوں
02:28ٹھیک ہے
02:29اب میں اس کو execute کرتا ہوں
02:30and now it's happy
02:31اور ہمارا x
02:32جو ہے original location پہ
02:33آ گیا ہوا ہے.
02:34لیکن اب
02:35تھوڑا سا problem ہے
02:36یا تو یہ
02:37کہ میں یہاں پہ
02:38multiple times
02:39let's say 10 times
02:41اس طرح کر سکتا ہوں
02:43ٹھیک ہے
02:44یہ ہمارا ایک بن جائے گا
02:45square
02:46ٹھیک ہے
02:47However
02:48ہم اس کو تھوڑا سا sophisticated
02:49طریقے سے کرنا چاہتے ہیں
02:50using for loop
02:51کو use کر
02:52میں اس کو کیسے
02:53print کر سکتا ہوں
02:54میں اس سب کو remove کرتا ہوں
02:55یہ statement رکھتا ہوں
02:56اور میں کہتا ہوں
02:57for i in range
02:59range
03:00اور range
03:01جو ہے ہماری
03:02canvas تک جائے گی
03:03ٹھیک ہے
03:04یہ میں کہتا ہوں canvas
03:05close کرتے ہیں for loop
03:06کو
03:07اور پھر
03:08آپ نے print کرنا ہے
03:09اترے times
03:10اب میں اس کو execute کرتا ہوں
03:11we will get the same result
03:12as you see
03:13this is cool
03:14ہاں
03:15اوکے
03:16تو اب ہم نے ایک square
03:17print کر لیا
03:18very good
03:19guys
03:20آپ نے ایک square
03:21print کیا
03:22اب میں آپ کو ایک اور challenge
03:23دینے لگا ہوں
03:24آپ
03:25same methodology
03:26لگا کے
03:27ایک triangle
03:28print کریے
03:29and let's see
03:30if you can do it

Recommended