Skip to content

Commit

Permalink
Cambios
Browse files Browse the repository at this point in the history
  • Loading branch information
indadominguez committed Oct 14, 2024
1 parent 8c8581b commit aecc6b8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/actividad_1_2_2.py
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()
12 changes: 12 additions & 0 deletions src/ej20.py
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.")
7 changes: 7 additions & 0 deletions src/ej21.py
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}")
8 changes: 8 additions & 0 deletions src/ej22.py
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)

0 comments on commit aecc6b8

Please sign in to comment.