generated from mwc/lab_iteration
	Modified square.py to use a for loop in order to simplify the code block.
1) I think coming from for loops in JS makes python for loops loops look a little weird sometime. But also utilizing list items as distances for Turtle is really cool, I didnt even think of that, im wondering if you could do the same on JS. It just looks a little different and obviously there are different use cases. 2)
This commit is contained in:
		
							
								
								
									
										14
									
								
								square.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								square.py
									
									
									
									
									
								
							@@ -1,16 +1,14 @@
 | 
			
		||||
from turtle import *
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def square(side_length):
 | 
			
		||||
    forward(side_length)
 | 
			
		||||
    right(90)
 | 
			
		||||
    forward(side_length)
 | 
			
		||||
    right(90)
 | 
			
		||||
    forward(side_length)
 | 
			
		||||
    right(90)
 | 
			
		||||
    forward(side_length)
 | 
			
		||||
    right(90)
 | 
			
		||||
    for i in range(4):
 | 
			
		||||
        forward(side_length)
 | 
			
		||||
        left(90)
 | 
			
		||||
        #forward(side_length)
 | 
			
		||||
 | 
			
		||||
sizes = [20, 40, 60, 80, 100]
 | 
			
		||||
for size in sizes:
 | 
			
		||||
    square(size)
 | 
			
		||||
 | 
			
		||||
done()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								test_louis.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								test_louis.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
from turtle import *
 | 
			
		||||
 | 
			
		||||
#creates a square function
 | 
			
		||||
def square(side_length):
 | 
			
		||||
    forward(side_length)
 | 
			
		||||
    right(90)
 | 
			
		||||
    forward(side_length)
 | 
			
		||||
    right(90)
 | 
			
		||||
    forward(side_length)
 | 
			
		||||
    right(90)
 | 
			
		||||
    forward(side_length)
 | 
			
		||||
    right(90)
 | 
			
		||||
 | 
			
		||||
#iterates through a list called size
 | 
			
		||||
sizes = [210, 410, 610, 810, 10]
 | 
			
		||||
for size in sizes:
 | 
			
		||||
    square(size)
 | 
			
		||||
		Reference in New Issue
	
	Block a user