-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic-operators.py
More file actions
128 lines (59 loc) · 1.67 KB
/
basic-operators.py
File metadata and controls
128 lines (59 loc) · 1.67 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'''
Arithmetic Operators
'''
number = 1 + 2 * 3 / 4.0
print(number)
# modulo (%) operators
remainder = 11 % 3
print(remainder)
'''
Using two multiplication symbols makes a power relationship.
'''
squared = 7 ** 2
cubed = 2 ** 3
print(squared)
print(cubed)
'''
python also support concatenating
'''
helloworld = "hello" + " " + "world"
print(helloworld)
'''
Python also supports multiplying strings to form a string with a repeating sequence:
'''
lotsofhellos = "hello" * 10
print(lotsofhellos)
'''
using operators with lists
'''
even_numbers = [2,4,6,8]
odd_numbers = [1,3,5,7]
all_numbers = odd_numbers + even_numbers
print(all_numbers)
'''
Just as in strings, Python supports forming new lists with a repeating sequence using the multiplication operator
'''
print([1,2,3] * 3)
'''
EXERCISE
The target of this exercise is to create two lists called x_list and y_list, which contain 10 instances of the variables x and y, respectively. You are also required to create a list called big_list, which contains the variables x and y, 10 times each, by concatenating the two lists you have created.
'''
# x = object()
# y = object()
# # TODO: change this code
# x_list = [x]
# y_list = [y]
# big_list = []
# print("x_list contains %d objects" % len(x_list))
# print("y_list contains %d objects" % len(y_list))
# print("big_list contains %d objects" % len(big_list))
# # testing code
# if x_list.count(x) == 10 and y_list.count(y) == 10:
# print("Almost there...")
# if big_list.count(x) == 10 and big_list.count(y) == 10:
# print("Great!")
'''
x_list = [1,2,3,4,5,6,7,8,9,10]
y_list = [1,2,3,4,5,6,7,8,9,10]
big_list = x_list + y_list
'''