This repository was archived by the owner on Jun 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced_loops.py
More file actions
98 lines (83 loc) · 2.34 KB
/
Copy pathadvanced_loops.py
File metadata and controls
98 lines (83 loc) · 2.34 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#Creates listOfStrings and assigns it a list of strings each with
#multiple words
listOfStrings = ["This is the first string", "This is the second string",
"This is the third string", "This is the fourth string",
"This is the fifth string"]
numSpaces = 0
#Loops over each string in listOfStrings
for currentString in listOfStrings:
#Loops over each character in currentString
for currentCharacter in currentString:
#Checks if the current character is a space
if currentCharacter == " ":
numSpaces += 1
numWords = numSpaces + len(listOfStrings)
print("There are", numWords, "words in these strings.")
############################################################
## multiplication table to 100
for i in range(1, 11):
for j in range(1, 11):
print(i, "times", j, "equals", i * j)
####################################################
## loop values - values of count
count = 0
for x in range(3):
for y in range(3):
count = count + y
print(count)
count = 0
for x in range(3):
for y in range(3):
count = count + x
print(count)
count = 0
for x in range(3):
for x in range(3):
count = count + x
print(count)
#############compare two list###############
list1 = ["Alison", "Mina", "Leticia", "Elaine", "Sonny", "Benito"]
list2 = ["Yuri", "Andrew", "Mina", "Elaine", "Charles", "Alison"]
for name1 in list1:
for name2 in list2:
if name1 == name2:
print(name1)
num = 5
result = 1
for i in range(1, num + 1):
result *= i
print(result)
###########################
## All the following loops have the same result
for i in range(1, 6):
j = 0
while j < i:
print(j, end=" ")
j += 1
print("")
for i in range(1, 6):
for j in range(0, i):
print(j, end=" ")
print("")
i = 0
while i < 6:
j = 0
while j < i:
print(j, end=" ")
j += 1
i += 1
print("")
#### EARWORM SOLUTION THAT PASSED ####
lyrics = ["I wanna be your endgame", "I wanna be your first string",
"I wanna be your A-Team", "I wanna be your endgame, endgame"]
lines_of_sanity = 3
count = 0
index = 0
while count < lines_of_sanity:
print(lyrics[index])
count += 1
index = (index + 1) % len(lyrics)
while index != 0:
print(lyrics[index])
index = (index + 1) % len(lyrics)
print("MAKE IT STOP")