-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c8581b
commit aecc6b8
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
def leer_numeros(): | ||
total = 0 | ||
contador = 0 | ||
|
||
while True: | ||
entrada = input("Introduce un número (o 'fin' para terminar): ") | ||
|
||
if entrada.lower() == "fin": | ||
break | ||
|
||
try: | ||
numero = float(entrada) | ||
total += numero | ||
contador += 1 | ||
except ValueError: | ||
print("Por favor, introduce un número válido o 'fin' para terminar.") | ||
|
||
return total, contador | ||
|
||
def calcular_media(total, contador): | ||
if contador == 0: | ||
return 0 | ||
return total / contador | ||
|
||
def main(): | ||
total, contador = leer_numeros() | ||
media = calcular_media(total, contador) | ||
|
||
print(f"Total: {total}") | ||
print(f"Cantidad de números: {contador}") | ||
print(f"Media: {media}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# ejercicio 20 | ||
|
||
n_º_telefono = input("Introduce un número de teléfono en el formato +34-número-extensión: ") | ||
|
||
if n_º_telefono.startswith("+34-") and n_º_telefono.count('-') == 2: | ||
|
||
no_prefijo = n_º_telefono.split('-') | ||
|
||
numero = no_prefijo[1] | ||
print("Número de teléfono:", numero) | ||
else: | ||
print("El formato del número de teléfono no es válido.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# ejercicio 21 | ||
|
||
frase = input("Introduce una frase: ") | ||
|
||
frase_invertida = frase[::-1] | ||
|
||
print(f"Fraase invertida: {frase_invertida}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# ejercicio 22 | ||
|
||
frase = input("Introduce una frase: ") | ||
vocal = input("Introduce una vocal: ") | ||
|
||
frase_vocal_mayuscula = frase.replace(vocal, vocal.upper()).replace(vocal.upper(),vocal.upper()) | ||
|
||
print("Frase con la vocal en mayúscula:", frase_vocal_mayuscula) |