forked from aluchici/cmi-portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-intro.py
More file actions
143 lines (120 loc) · 2.56 KB
/
Copy pathpython-intro.py
File metadata and controls
143 lines (120 loc) · 2.56 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
variable1 = 23
variable2 = "aceasta este o variabla"
# numbers
variable3 = 30
variable4 = 33.22
variable5 = 0.0000000001
print(variable5)
# boolean
variable6 = True
variable7 = False
# strings
variable8 = "acesta este un text intre ghilimele 3434 %%£@ if for def"
variable9 = 'fsrtdfsdjfksd fdkslfkdls fdkslfkds fsdlfkdslfk fdsfsd erwerewrew ewrwre309420490234923 irulgk'
variable10 = variable8.upper()
variable11 = variable8.find("este")
print(variable11)
variable8 = 'dksajdkjsad'
print(variable8)
# sequences
# lists
l1 = [1, 2, 3, "string", True, False, 23.0, 22.10]
el1 = l1[2]
l1[0] = "first element"
l1[-1] = "last element"
els = l1[2:5]
print(el1)
print(l1)
print(els)
l1.append("appended element")
l2 = [2, 324, 121, 99]
l2.sort(reverse=True)
print(l2)
# mappings
d1 = {
"name": "andrei",
"age": 32,
"country": "romania",
1: "ceva valoare"
}
d2 = {
"name": "ii",
"age": 33,
"country": "romania",
1: "alta valoare"
}
d1["country"] = "ro"
d1.update({2: "a"})
print(d1)
print(d1["country"])
l3 = [d1, d2]
print( l3[1]["country"] )
# logical operators
# a == b a is equal to b
# a != b a is not equal to b
# a > b a is greater than b
# a >= b a is greater than or equal to b
# a <= b a is less than or equal to b
# not True --> False
# not ((a == b) and ((c > d) or (c == a))))
# and --> True iff ambii termeni sunt adevarati
# or --> sau False iff ambii termeni sunt falsi
# arithmetic operators
# + ( a + b )
# - ( a - b )
# / ( a / b )
# * ( a * b )
# ** ( a ** b )
# % ( restul impartirii celor doua numere, eg 3 % 2 = 1)
# a % 2 == 0 --> check if a is even
# a % 2 == 1 --> check if a is odd
# if elif else
# daca a % 2 == 0
# print(a)
# a = a * 2
# altfel
# print(a)
# a = a * 3
a = 11
if a % 2 == 0:
print('is even', a)
a = a * 2
elif a % 2 == 1 and a > 10:
print('is odd & greater than 10', a)
else:
print('is odd', a)
a = a * 3
print(a)
# for
# pentru fiecare element din sequence
# executa instructiunile de aici
# pentru a intre 1 si 10
# executa intructiunile de aici
for i in l3:
print(i)
for i in range(0, 10):
print(i, i*2)
if a % 2 == 1:
for i in range(0, a):
print(i)
for i in range(0, a):
if i % 2 == 1:
print(i)
# while
# cat timp ceva este adevarat
# executa instructiunile de aici
while a > 0:
print(a)
a = a - 1
# sequences bonus
# tuples
t1 = (1, 2, 3, 2, 2)
print('tuple', t1[2])
print(t1.count(2))
print(t1.index(3))
# set
s1 = {1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1}
print(s1)
s1.add(3)
print(s1.difference({2,2,11}))
print(s1.union({2,2,11}))