-
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.
Merge branch 'main' of github.com:IES-Rafael-Alberti/dam1-2425-ejerci…
…cios-u2-dcsibon
- Loading branch information
Showing
36 changed files
with
836 additions
and
12 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 @@ | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
|
Empty file.
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,55 @@ | ||
""" | ||
Ejercicio 2.1.1 | ||
Escribir un programa que pregunte al usuario su edad y muestre por pantalla si es mayor de edad o no. | ||
""" | ||
|
||
def pedirEdad(): | ||
""" | ||
Pedir la edad y comprobar que se trata de un número entero entre 1 y 125. | ||
Retorna | ||
------- | ||
int | ||
un entero con el valor de la edad introducida por consola. | ||
""" | ||
salir = False | ||
while not salir: | ||
entrada = input("Introduzca su edad: ") | ||
|
||
if entrada.isnumeric() and 0 < int(entrada) <= 125: | ||
salir = True | ||
else: | ||
print("***Error*** edad introducida no válida.") | ||
|
||
edad = int(entrada) | ||
|
||
return edad | ||
|
||
|
||
def mayorEdad(edad): | ||
""" | ||
Comprobar si la edad corresponde a una persona mayor de edad o no. | ||
Retorna | ||
------- | ||
bool | ||
True es mayor de edad / False no es mayor de edad. | ||
""" | ||
if edad >= 18: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
def main(): | ||
edad = pedirEdad() | ||
|
||
if mayorEdad(edad): | ||
print("Eres mayor de edad.") | ||
else: | ||
print("No eres mayor de edad.") | ||
|
||
|
||
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,119 @@ | ||
""" | ||
Ejercicio 2.1.10 | ||
La pizzería Bella Napoli ofrece pizzas vegetarianas y no vegetarianas a sus clientes. Los ingredientes para cada tipo de pizza aparecen a continuación. | ||
- Ingredientes vegetarianos: Pimiento y tofu. | ||
- Ingredientes no vegetarianos: Peperoni, Jamón y Salmón. | ||
Escribir un programa que pregunte al usuario si quiere una pizza vegetariana o no, y en función de su respuesta le muestre un menú con los ingredientes disponibles para que elija. Solo se puede eligir un ingrediente además de la mozzarella y el tomate que están en todas la pizzas. Al final se debe mostrar por pantalla si la pizza elegida es vegetariana o no y todos los ingredientes que lleva. | ||
""" | ||
|
||
import os | ||
|
||
|
||
def preguntarTipoPizza(): | ||
""" | ||
Pedir el tipo de la pizza. | ||
Retorna | ||
------- | ||
int un entero con el valor del tipo de pizza => 1: vegetariana / 2: no vegetariana | ||
""" | ||
tipo = -1 | ||
while tipo != 1 and tipo != 2: | ||
tipo = pedirNumero("Elija el tipo de pizza (1. vegetariana / 2. NO vegetariana) => ", 1, 2) | ||
if tipo == -1: | ||
print("**ERROR** tipo de pizza no válido...") | ||
|
||
return tipo | ||
|
||
|
||
def obtenerListaIngredientes(tipo): | ||
""" | ||
Obtener los ingredientes según el tipo de pizza. | ||
Params | ||
---------- | ||
int tipo de pizza => 1 = vegetariana / 2 = no vegetariana | ||
Retorna | ||
------- | ||
str una cadena de caracteres con los ingredientes de cada pizza. | ||
""" | ||
if tipo == 1: | ||
# pizza vegetariana | ||
lista = ["pimiento", "tofu"] | ||
elif tipo == 2: | ||
# pizza no vegetariana | ||
lista = ["peperoni", "salmón", "jamón"] | ||
else: | ||
# error, pizza no válida | ||
lista = [] | ||
return lista | ||
|
||
|
||
def muestraIngredientes(listaIngredientes): | ||
resultadoPantalla = "" | ||
cont = 1 | ||
for ingrediente in listaIngredientes: | ||
resultadoPantalla += str(cont) + " - " + ingrediente + "\n" | ||
cont += 1 | ||
return resultadoPantalla | ||
|
||
|
||
def eligeIngrediente(listaIngredientes): | ||
print("\nIngredientes disponibles para esta pizza") | ||
print("----------------------------------------") | ||
print(muestraIngredientes(listaIngredientes)) | ||
|
||
ingredienteExtra = -1 | ||
while ingredienteExtra == -1: | ||
ingredienteExtra = pedirNumero("Elige el ingrediente extra de tu pizza: ", 1, len(listaIngredientes)) | ||
if ingredienteExtra == -1: | ||
print("**Error** elige un número válido de la lista...") | ||
return ingredienteExtra | ||
|
||
|
||
def pedirNumero(mensaje, min, max): | ||
entrada = input(mensaje) | ||
if entrada.isnumeric() and min <= int(entrada) <= max: | ||
return int(entrada) | ||
else: | ||
return -1 | ||
|
||
|
||
def mostrarPizza(tipo, listaIngredientes, ingrediente): | ||
frase = "\nHas elegido una pizza " | ||
if tipo == 1: | ||
frase += "vegetariana con tomate, mozzarella y " | ||
else: | ||
frase += "no vegetariana con tomate, mozzarella y " | ||
frase += listaIngredientes[ingrediente - 1] + ".\n" | ||
return frase | ||
|
||
|
||
def borrarConsola(): | ||
if os.name == "posix": | ||
os.system ("clear") | ||
elif os.name == "ce" or os.name == "nt" or os.name == "dos": | ||
os.system ("cls") | ||
|
||
|
||
def main(): | ||
borrarConsola() | ||
|
||
print("\nBienvenido a la pizzería Bella Napoli...\n") | ||
|
||
tipo = preguntarTipoPizza() | ||
|
||
listaIngredientes = obtenerListaIngredientes(tipo) | ||
|
||
if len(listaIngredientes) > 0: | ||
ingrediente = eligeIngrediente(listaIngredientes) | ||
|
||
print(mostrarPizza(tipo, listaIngredientes, ingrediente)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
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,27 @@ | ||
""" | ||
Ejercicio 2.2.1 | ||
Escribir un programa que pida al usuario una palabra y la muestre por pantalla 10 veces. | ||
""" | ||
|
||
import os | ||
|
||
def repetirPalabra(palabra): | ||
for i in range(1, 10): | ||
palabra += palabra + "\n" | ||
|
||
|
||
def borrarConsola(): | ||
if os.name == "posix": | ||
os.system ("clear") | ||
elif os.name == "ce" or os.name == "nt" or os.name == "dos": | ||
os.system ("cls") | ||
|
||
|
||
def main(): | ||
borrarConsola() | ||
palabra = input("Introduzca una palabra: ").replace(" ", "") | ||
print(repetirPalabra(palabra)) | ||
|
||
|
||
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,53 @@ | ||
""" | ||
Ejercicio 2.2.3 | ||
Escribir un programa que pida al usuario un número entero positivo y muestre por pantalla todos los números impares desde 1 hasta ese número separados por comas. | ||
""" | ||
|
||
import os | ||
|
||
def comprobarNumero(entrada): | ||
return entrada.isnumeric() and int(entrada) > 0 | ||
|
||
|
||
def pedirNumeroEnteroPositivo(mensaje: str): | ||
entrada = input(mensaje).replace(" ", "") | ||
|
||
while not comprobarNumero(entrada): | ||
entrada = input("**ERROR**, vuelva a intentarlo\n" + mensaje).replace(" ", "") | ||
|
||
#Retornamos el número entero positivo introducido | ||
return int(entrada) | ||
|
||
|
||
def crearSerie(numero): | ||
serie = "" | ||
for i in range(1, numero, 2): | ||
serie += str(i) | ||
if i < numero - 1: | ||
serie += ", " | ||
return serie | ||
|
||
|
||
def esPar(numero): | ||
return numero % 2 == 0 | ||
|
||
|
||
def borrarConsola(): | ||
if os.name == "posix": | ||
os.system ("clear") | ||
elif os.name == "ce" or os.name == "nt" or os.name == "dos": | ||
os.system ("cls") | ||
|
||
|
||
def main(): | ||
borrarConsola() | ||
numero = pedirNumeroEnteroPositivo("Introduzca un entero positivo: ") | ||
|
||
if not esPar(numero): | ||
numero += 1 | ||
|
||
print(crearSerie(numero)) | ||
|
||
|
||
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,27 @@ | ||
""" | ||
Ejercicio 2.2.4 | ||
Escribir un programa que pida al usuario un número entero positivo y muestre por pantalla la cuenta atrás desde ese número hasta cero separados por comas. | ||
""" | ||
|
||
import os | ||
from ej2_23 import pedirNumeroEnteroPositivo, borrarConsola | ||
|
||
|
||
def crearSerie(numero): | ||
serie = "" | ||
for i in range(numero, -1, -1): | ||
serie += str(i) | ||
if i > 0: | ||
serie += ", " | ||
return serie | ||
|
||
|
||
def main(): | ||
borrarConsola() | ||
numero = pedirNumeroEnteroPositivo("Introduzca un entero positivo: ") | ||
|
||
print(crearSerie(numero)) | ||
|
||
|
||
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,51 @@ | ||
""" | ||
Ejercicio 2.2.5 | ||
Escribir un programa que pregunte al usuario una cantidad a invertir, el interés anual y el número de años, y muestre por pantalla el capital obtenido en la inversión cada año que dura la inversión. | ||
# Formula para calcular El capital tras un año. | ||
amount *= 1 + interest / 100 | ||
# En donde: | ||
# - amount: Cantidad a invertir | ||
# - interest: Interes porcentual anual | ||
""" | ||
|
||
from EjerciciosU2.Pract2_2.ej2_2_03 import borrarConsola, pedirNumeroEnteroPositivo | ||
|
||
|
||
def comprobarFloat(entrada: str): | ||
return entrada.count(".") <= 1 and entrada.replace(".", "").isnumeric() | ||
|
||
|
||
def pedirNumeroFloat(mensaje: str): | ||
entrada = input(mensaje).replace(" ", "") | ||
|
||
while not comprobarFloat(entrada): | ||
entrada = input("**ERROR**, entrada no válida\n" + mensaje).replace(" ", "") | ||
|
||
#Retornamos el número introducido convertido a float | ||
return float(entrada) | ||
|
||
|
||
def rendimientoCapital(capital: float, interes: float, annios: int): | ||
|
||
rendimientoAnual = "" | ||
cont = 1 | ||
|
||
while cont <= annios: | ||
capital *= 1 + interes / 100 | ||
rendimientoAnual += "Año {:>2} => {:.2f}\n".format(cont, capital) | ||
cont += 1 | ||
|
||
return rendimientoAnual | ||
|
||
def main(): | ||
borrarConsola() | ||
|
||
capital = pedirNumeroFloat("Introduzca el capital invertido: ") | ||
interes = pedirNumeroFloat("Introduzca el interés del fondo: ") | ||
annios = pedirNumeroEnteroPositivo("Introduzca el número de años a invertir: ") | ||
|
||
print(rendimientoCapital(capital, interes, annios)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.