Skip to content

Commit 1aaa1dc

Browse files
committed
04 - Python
1 parent 85cda8e commit 1aaa1dc

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
mensaje = 'Hola Mundo' # Declaración de variables
2+
3+
# Concatenación de caracteres
4+
mensaje1 = 'Hola' + ' ' + 'Mundo'
5+
print(mensaje1)
6+
7+
# Multiplicación de caracteres
8+
mensaje2A = 'Hola ' * 3
9+
mensaje2B = 'Mundo'
10+
print(mensaje2A + mensaje2B)
11+
12+
# Añadir caracteres (desde aquí 'String Methods')
13+
mensaje3 = 'Hola'
14+
mensaje3 += ' '
15+
mensaje3 += 'Mundo'
16+
print(mensaje3)
17+
18+
# Extensión de caracteres
19+
mensaje4 = 'hola' + ' ' + 'mundo'
20+
print(len(mensaje4))
21+
22+
# Encontrar caracteres
23+
mensaje5 = "Hola Mundo"
24+
mensaje5A = mensaje5.find("Mundo")
25+
print(mensaje5A)
26+
27+
# Minúsculas
28+
mensaje6 = "HOLA MUNDO"
29+
mensaje6A = mensaje6.lower()
30+
print(mensaje6A)
31+
32+
# Reemplazo
33+
mensaje7 = "Hola mundo"
34+
mensaje7A = mensaje7.replace("L", "pizza")
35+
print(mensaje7A)
36+
37+
"""
38+
Extra
39+
"""
40+
def check(word1: str, word2: str):
41+
# Palíndromos
42+
print(f"¿{word1} es un palíndromo? {word1 == word1[::-1]}")
43+
print(f"¿{word2} es un palíndromo? {word2 == word2[::-1]}")
44+
45+
# Anagrama
46+
print(f"¿{word1} es un anagrama de {word2}? {sorted(word1) == sorted(word2)}")
47+
48+
# Isogramas
49+
50+
def isogram(word: str) -> bool:
51+
wordDict = dict()
52+
for word in word1:
53+
wordDict[word] = wordDict.get(word, 0) + 1
54+
55+
isogram = True
56+
values = list(wordDict.values())
57+
print(values)
58+
isogramLen = values[0]
59+
for wordCount in values:
60+
if wordCount != isogramLen:
61+
isogram = False
62+
break
63+
64+
return isogram
65+
66+
67+
print(f"¿{word1} es un isograma? {isogram(word1)}")
68+
print(f"¿{word2} es un isograma? {isogram(word2)}")
69+
70+
71+
print(isogram)
72+
73+
check("radar", "reconocer")
74+
check("amor", "roma")

0 commit comments

Comments
 (0)