-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.py
105 lines (79 loc) · 2.35 KB
/
testing.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
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
99
100
101
102
103
104
105
# Example 2
def main():
# Create an empty list that will hold fabric names.
fabrics = []
# Add three elements at the end of the fabrics list.
fabrics.append("velvet")
fabrics.append("denim")
fabrics.append("gingham")
# Insert an element at the beginning of the fabrics list.
fabrics.insert(0, "chiffon")
print(fabrics)
# Determine if gingham is in the fabrics list.
if "gingham" in fabrics:
print("gingham is in the list.")
else:
print("gingham is NOT in the list.")
# Get the index where velvet is stored in the fabrics list.
i = fabrics.index("velvet")
# Replace velvet with taffeta.
fabrics[i] = "taffeta"
# Remove the last element from the fabrics list.
# fabrics.pop()
# Remove denim from the fabrics list.
fabrics.remove("denim")
# Get the length of the fabrics list and print it.
n = len(fabrics)
print(f"The fabrics list contains {n} elements.")
print(fabrics, i)
# Example 3
def main():
# Create a list of color names.
colors = ["red", "orange", "yellow", "green", "blue"]
# Use a for loop to print each element in the list.
for color in colors:
print(f' the color is {color} ')
# Example 4
def main():
# Count from zero to nine by one.
for i in range(10):
print(i)
print()
# Count from five to nine by one.
for i in range(5, 10):
print(i)
print()
# Count from zero to eight by two.
for i in range(0, 10, 2):
print(i)
print()
# Count from 100 down to 70 by three.
for i in range(100, 69, -3):
print(i)
# Example 5
def main():
# Create a list of color names.
colors = ["red", "orange", "yellow", "green", "blue"]
# Use a for loop to print each element in the list.
for color in colors:
print(color)
print()
# Use a different for loop to
# print each element in the list.
for i in range(len(colors)):
# Use the index i to retrieve
# an element from the list.
color = colors[i]
print(color)
# Call main to start this program.
# if __name__ == "__main__":
# main()
# Call main to start this program.
# if __name__ == "__main__":
# main()
# Call main to start this program.
if __name__ == "__main__":
main()
# Call main to start this program.
# if __name__ == "__main__":
# main()