-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeek3-For_Loops.py
59 lines (44 loc) · 1.71 KB
/
Week3-For_Loops.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
for x in range(5):
print(x)
####################################################################################
####################################################################################
def square(n):
return n*n
def sum_squares(x):
sum = 0
for n in range(x):
sum += square(n)
return sum
print(sum_squares(10)) # Should be 285
####################################################################################
####################################################################################
print ("XXXXXXXXXXXXXXXXX")
def factorial(n):
result = 1
for i in range(1,n):
#result = result + i*result
result += i * result
return result
print(factorial(4)) # should return 24
print(factorial(5)) # should return 120
####################################################################################
####################################################################################
print ("XXXXXXXXXXXXXXXXX")
teams = [ 'Dragons', 'Wolves', 'Pandas', 'Unicorns']
for home_team in teams:
for away_team in teams:
if home_team != away_team:
print ("Scheudle: " + home_team + " VS " + away_team)
####################################################################################
####################################################################################
for left in range(7):
for right in range(left,7):
print "["+str(left)+"|"+str(right)+"]",
print
####################################################################################
####################################################################################
def factorial(n):
if n < 2:
return 1
return n * factorial(n-1)
print (factorial(9))