– Loop Solutions

2 Loop Solutions

 1: def oneToTen():
 2:         for i in range(1,11):
 3:                 print(i)
 4: 
 5: def oneToTenAcross():
 6:       print("|", end="")
 7:         for i in range(1,11):
 8:                 print(i,"|",end="")
 9: 
10: def oddNumbers():
11:         for i in range(1,21,2):
12:                 print(i)
13: 
14: def squares():
15:         for i in range(1,11):
16:                 print(i*i)
17: 
18: def random4():
19:         for i in range(1,5):
20:                 print(random.randint(1,10))
21: 
22: def even(n):
23:         for i in range(1,n+1):
24: 
25: 
26: def powers(n):
27:         for i in range(1,n+1):
28:                 print(2**i)
29: 
30: def triangle():
31:         for i in range(1,6):
32:                 for j in range(1,i+1):
33:                         print("*", end = "")
34:                 print()
35: 
36: def areWeThereYet():
37:         s = "no"
38:         while (s != "yes"):
39:                 s = input("Are we there yet?")
40:         print ("Good!")
41: 
42: 
43: def tableSquare():
44:         for i in range(1,5):
45:                 for j in range (1, 5):
46:                         print("|",i*j, "\t", end = "")
47:                 print("|")
48: 
49: def tableSquares(n):
50:         for i in range(1,n+1):
51:                 for j in range (1, n+1):
52:                         print("|",i*j, "\t", end = "")
53:                 print("|")

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.