-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_Operadores.py
163 lines (122 loc) · 4.09 KB
/
1_Operadores.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
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
144
145
146
147
148
149
150
151
152
153
154
# Numeric Types and Operators #
# To complex
# ---------------------------------------------
import datetime
import re
a = 3
complex_a = complex(a)
print('a: ', complex_a, type(complex_a))
# --> (3+0j) <class 'complex'>
b = 7.5
complex_b = complex(b)
print('b: ', complex_b, type(complex_b))
# --> (7.5+0j) <class 'complex'>
# To_int
# ---------------------------------------------
c = 34.54
int_c = int(c)
print('c: ', int_c, type(int_c))
# --> c: 34 <class 'int'>
# d = (3+7j)
# int_d = int(d)
# print('d: ', int_d, type(int_d))
# --> TypeError: can't convert complex to int
# To_float
# ---------------------------------------------
e = 7
float_e = float(e)
print('e: ', float_e, type(float_e))
# --> e: 7.0 <class 'float'>
# f = (7+3j)
# float_f = float(f)
# print('f: ', float_f, type(float_f))
# --> TypeError: can't convert complex to float
# Other operators #
g = abs(-3.5)
h = abs(-456)
i = abs(-3-5j)
j = divmod(34, 7)
k = pow(2, 5)
conjugate = (-3-7j).conjugate()
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
hechizo = "Alojomora"
magia = 20
if hechizo == "Expeliarmus":
magia -= 5
print('Expeliarmus - Magia: ', magia)
elif hechizo == "Alojomora":
magia += 5
print('Alojomora - Magia: ', magia)
else:
print('Hechizo desconocido')
# --> Alojomora - Magia: 25
# ------------------------------------------------------------------------------------------------------------------- #
altura = 3
for i in range(altura):
pass
print('\n')
# STRING FORMATTING #
num = 123.45678
print('THE OLD WAY \n')
# Formatting the old way
print('Hello, this number %s is my magical number' %num) # Whatever go to string
print('Hello, this number %d is my magical number' %num) # Number to INT
print('Hello, this number %f is my magical number' %num) # Number to FLOAT with 6 decimals default
print('Hello, this number %.3f is my magical number' %num) # Specify the number of decimals (3)
print('Hello, this number %10.3f is my magical number' %num) # Specify the minimun width (10)
print('\n')
print('THE NEW WAY \n')
# Formatting the new way
print(f'Hello, this number {num} is my magical number')
# print(f'Hello, this number {num:d} is my magical number') # Error
print(f'Hello, this number {num:f} is my magical number')
print(f'Hello, this number {num:.3f} is my magical number')
print(f'Hello, this number {num:10.3f} is my magical number')
print('\n')
print('Other Examples \n')
n = 123456789
print(f'{n:,}')
d = datetime.datetime(1989, 3, 31, 11, 10, 30)
print(f'Mi fecha de nacimiento es {d:%Y-%m-%d %H:%M:%S}')
a = 'Hola holita vecinitos' # len 21
print(f'{a:50} es la famosa frase de Ned Flanders')
print(f'{a:30} es la famosa frase de Ned Flanders')
x = 44
print(f"El numero {x} --> int: {x:d}; hex: {x:x}; oct: {x:o}; bin: {x:b}")
# def caracteres(cadena):
# d={}
# for c in cadena:
# d[c] += d.get(c, 1)
# return d
#
#
# car = caracteres('Hola que tal!')
# print(car)
#
# # EXPRESIONES REGULARES CLASE
#
# VALIDAR POSICIONES DE AJEDREZ: ([A-H][1-8])*$
# VALIDAR UN NÚMERO EN HEXADECIMAL: ([0-9a-fA-F])+$
# Nombre de variable válida: [-]*[a-z]+[0-0a-zA-Z_]*$
# Contraseña de 8 o más números y letras: [0-9a-zA-Z]{8}[0-9a-zA-Z]*$
#
# len(re.findAll(r'\besta\b', cadena)) #Esta estantería está atestada
lista = [1,34,654,7,23,5678]
def format_numbers(lista):
n = len(max(lista))
r = []
for l in lista:
# added_ceros = pos - len(str(l))
# num = '0'*added_ceros+str(l)
r.append(str(e).zfill(n+1))
return r
frase = 'Hola capitán, mi capitán, "al abordaje" , nwerwer wer "fgfgfg" sfsrf'
# print(re.match(r'".*$"', frase))
# re.findall(r'".*$"', frase)
# re.sub
#
# python ejercicio pilas y colas y ver con que estructura
# crear listas, tuplas, dic vacias. conjunto vacío-> set
# Para inicializar variables mejor con las funciones
#