Codes for quilting: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
==Basic== | |||
<source lang=python> | |||
<b>loops</b><br/> | <b>loops</b><br/> | ||
for x in range(10): | for x in range(10): | ||
Line 45: | Line 46: | ||
for y in range(1,6): | for y in range(1,6): | ||
print('x'* x, 'y'* y) | print('x'* x, 'y'* y) | ||
</source> |
Revision as of 12:59, 22 October 2020
Basic
<b>loops</b><br/>
for x in range(10):
print ("hello python")
print (x)
x = 1
while x<10:
print (f"x is {x}")
x = x + 1
<b>.random</b><br/>
words.sort()
words = ['weaving', 'with', 'words', 'and', 'code']
# First a simple loop through the list
for word in words:
print(word)
# Then, a loop in which we start to play with random again
import random
for word in words:
print(random.choice(words), random.choice(words), random.choice(words), random.choice(words), random.choice(words))
# How to work with more iterations of the loop?
# For example 100?
# You can use "range"
range?
# Make a loop that starts at 0 and ends at 99 (100 iterations)
import random
for number in range(100):
print(random.choice(words), random.choice(words), random.choice(words), random.choice(words), random.choice(words))
# You can use range also differently, for example to loop in between two numbers ...
for number in range(50, 60):
print(number, 'x'* number)
# ... or with bigger steps:
for number in range(0,100,10):
print(number, '*'* number)
# Now... write a loop in a loop
for x in range(1,6):
for y in range(1,6):
print('x'* x, 'y'* y)