1
+ # asignement operator
2
+ n1 = 10
3
+ n2 = 3
4
+ n1 += 2 # same that n1 = n1 + 2
5
+
6
+ # Aricmethic operators
7
+ add = 2 + 2
8
+ sub = 3 - 2
9
+ mult = 5 * 2
10
+ div = 10 * 2 # 5.0 (Division always return a float number)
11
+ mod = 10 % 3 # Module (return the reaminder) 1
12
+ floor_division = 10 // 3 # 3, Return a integer of division
13
+ exponential = 2 ** 3 # 2 * 2 * 2
14
+
15
+ #Logic operators
16
+ """
17
+ AND = Return True if both conditions are true
18
+ OR = Return True if one of the statement is true
19
+ NOT = Invert the result, if not True = False
20
+ """
21
+ print (3 < 5 and 4 < 5 ) # True
22
+ print (3 < 5 and 5 < 5 ) #False
23
+ print (3 < 5 or 5 < 5 ) #True
24
+ print (3 < 2 or 4 < 2 ) #False
25
+ print (not True ) #False
26
+ print (not False ) #True
27
+
28
+ #Comparison operators
29
+ """
30
+ == equal
31
+ > mayor than
32
+ >= mayor or equal than
33
+ < menor than
34
+ <= menor or equal than
35
+ != not equal or diferent
36
+ """
37
+ print ("-----Comparison Operators-----" )
38
+ print (3 == 2 ) # False
39
+ print (3 == 3 ) #True
40
+ print (3 > 2 ) #True
41
+ print (3 > 3 ) #False
42
+ print (5 >= 2 ) #True
43
+ print (2 >= 3 ) #False
44
+ print (2 < 3 ) #True
45
+ print (3 < 2 ) # False
46
+ print (2 <= 2 ) #True
47
+ print (2 <= 1 ) #False
48
+ print (2 != 3 ) #True
49
+ print (3 != 3 ) #False
50
+
51
+ print ("-----Identity Operators-----" )
52
+ """
53
+ Identity Operators are used to compare objects
54
+ IS = is the same object?
55
+ IS NOT = Is no the same object
56
+ """
57
+ x = 10
58
+ y = 8
59
+ print (x is 5 + 5 ) # True, because 10 is equal that 5+5=10
60
+ print (y is not 4 * 2 ) # False, because 8 is 8
61
+
62
+ print ("-----Membership operators-----" )
63
+ """
64
+ Are used to test if a statement is present in an object
65
+ IN = Return True if a Sequence specific in an object
66
+ NOT IN = Return True if a statement specific is not present in the object
67
+ """
68
+ print (f"'D' in 'Duban:' { 'D' in 'Duban' } " )
69
+ print (f"'S' not in 'Duban': { 'S' not in 'Duban' } " ) #True
70
+
71
+
72
+ print ("-----Bit Operators-----" )
73
+ """
74
+ Integer numbers to binary numbers
75
+ AND (&)
76
+ OR (|)
77
+ XOR (^)
78
+ NOT (~)
79
+ MOVE TO RIGHT (>>)
80
+ MOVE TO LEFT (<<)
81
+ """
82
+ a = 10 # 1010
83
+ b = 3 # 0011
84
+
85
+ print (f"AND: 10 & 3 = { a & b } " ) # 0010 = 2
86
+ print (f"OR: 10 | 3 = { a | b } " ) # 1011 = 11
87
+ print (f"XOR: 10 ^ 3 = { a ^ b } " ) # 1001 = 9
88
+ print (f"NOT: { ~ 10 } " )
89
+ print (f"Desplazamiento a la derecha: 10 >> 2 = { 10 >> 2 } " ) # 0010 = 2
90
+ print (f"Desplazamiento a la izquierda: 10 << 2 = { 10 << 2 } " ) # 101000 = 40
91
+
92
+
93
+ print ("-----Control estructures-----" )
94
+ #Conditionals
95
+ """
96
+ if- elif - else
97
+ """
98
+ print ("IF STATEMENT" )
99
+ grade = - 1
100
+ if 9 <= grade <= 10 : # if
101
+ print ("Excelent" )
102
+ elif 6 <= grade < 9 : # elif
103
+ print ("Aprobbed" )
104
+ elif 0 <= grade <= 5 :
105
+ print ("Reprobbed" )
106
+ else :
107
+ print ("Invalid grade" )
108
+
109
+ # Iteratives
110
+
111
+ """
112
+ while
113
+ """
114
+ counter = 1
115
+ while counter <= 10 :
116
+ print (counter )
117
+ counter += 1
118
+
119
+ # for
120
+ # Using the range function
121
+ my_list = ["Orange" , "Pineapple" , "Strawberry" , "Watermelon" ]
122
+ for i in my_list :
123
+ print (i ) # Print each element of my list
124
+
125
+ #try - except
126
+
127
+ try :
128
+ number = int (input ("enter a int number: " ))
129
+ except :
130
+ print ("X is not integer" )
131
+ else :
132
+ print (f"your number: { number } " )
133
+ finally :
134
+ print ("Continue with the program" )
135
+
136
+
137
+ """Extra difficulty"""
138
+
139
+ for num in range (10 ,56 ):
140
+ if num % 2 == 0 and num != 16 and num % 3 != 0 :
141
+ print (num )
0 commit comments