python_by_example/basic/basic02.py

105 lines
4.3 KiB
Python
Raw Permalink Normal View History

2023-11-09 17:45:00 -03:00
class basics_002():
def mayor(self):
"""Ask for two numbers. If the first one is larger than the second, display
the second number first and then the first number, otherwise show the first
number first and then the second."""
num_1 = int(input("Ingresa un número :"))
num_2 = int(input("Ingresa otro número :"))
if num_1 > num_2:
print(f"{num_2} {num_1}")
elif num_1 < num_2:
print(f"{num_1} {num_2}")
else:
print(f"{num_1} = {num_2}")
def muy_alto(self):
"""Ask the user to enter a number that is under 20. If they enter a number that
is 20 or more, display the message Too high, otherwise display Thank you."""
num = int(input("Ingresa un número menor que 20: "))
if num >= 20:
print("Muy Alto!")
else:
print("Gracias")
def gracias(self):
"""Ask the user to enter a number between 10 and 20 (inclusive). If they enter a
number within this range, display the message Thank you, otherwise display the
message Incorrect answer."""
num = int(input("Ingresa un número entre 10 y 20: "))
if 10 <= num <= 20:
print("Gracias")
else:
print("El número no es válido")
def fav_color(self):
"""Ask the user to enter their favourite colour. If they enter “red”, “RED” or
Red display the message I like red too, otherwise display the message
2023-11-17 13:26:09 -03:00
I don't like [colour], I prefer red”."""
2023-11-09 17:45:00 -03:00
color = input("¿Cual es tu color favorito?: ")
match color.lower():
case "rojo":
print(f"A mi también me gusta el {color.capitalize()}")
case _:
print(f"No me gusta el {color.capitalize()}, prefiero el Rojo")
def clima(self):
"""Ask the user if it is raining and convert their answer to lower case
2023-11-17 13:26:09 -03:00
so it doesn't matter what case they type it in. If they answer “yes”,
2023-11-09 17:45:00 -03:00
ask if it is windy. If they answer yes to this second question,
display the answer It is too windy for an umbrella, otherwise
display the message Take an umbrella. If they did not answer yes
to the first question, display the answer Enjoy your day."""
llueve = input("¿Está lloviendo?: ").lower()
if llueve == "si":
viento = input("¿Hay viento?: ").lower()
if viento == "si":
print("Es mala idea llevar paraguas")
else:
print("Lleva tu paraguas")
else:
print("Disfruta del día")
def edad_conducir(self):
2023-11-17 13:26:09 -03:00
"""Ask the user's age. If they are 18 or over, display the message \"You
2023-11-09 17:45:00 -03:00
can vote\", if they are aged 17, display the message \"You can learn to
drive\", if they are 16, display the message \"You can buy a lottery
ticket\", if they are under 16, display the message \"You can go
Trick-or-Treating\"."""
edad = int(input("Ingresa tu edad: "))
if edad >= 18:
print("Puedes votar")
if edad == 17:
print("Puedes aprender a conducir")
if edad == 16:
print("Puedes comprar un ticket de azar")
if edad < 16:
print("Puedes salir ir jugar en la arena")
def alto_bajo(self):
"""Ask the user to enter a number. If it is under 10, display the message
\"Too low\", if their number is between 10 and 20, display \"Correct\",
otherwise display \"Too high\""""
num = int(input("Ingresa un número: "))
if num < 10:
print("El número es muy bajo")
elif 10 <= num <= 20:
print("Correcto")
else:
print("Muy alto")
def uno_dos_tres(self):
"""Ask the user to enter 1, 2 or 3. If they enter a 1, display the message
\"Thank you\", if they enter a 2, display \"Well done\", if they enter a 3,
display \"Correct\". If they enter anything else, display \"Error message\"."""
num = int(input("Ingresa 1 , 2 o 3: "))
match num:
case 1:
print("Gracias")
case 2:
print("Bién hecho")
case 3:
print("Correcto")
case _:
print("Error")