90 lines
3.9 KiB
Python
90 lines
3.9 KiB
Python
class basics_001:
|
||
|
||
def hola(self):
|
||
"Ask for the user's first name and display the output message."
|
||
nombre = input("Ingresa tu primer nombre: ")
|
||
print(f"Hola {nombre}")
|
||
|
||
def hola2(self):
|
||
"""Ask for the user’s first name and then ask for their surname
|
||
and display the output message Hello [First Name] [Surname]."""
|
||
nombre = input("Ingresa tu primer nombre: ")
|
||
apellido = input("Ingresa tu apellido: ")
|
||
print(f"Hola {nombre} {apellido}")
|
||
|
||
def pez(self):
|
||
"""Write code that will display the joke \"What do you call a bear
|
||
with no teeth?\" and on the next line display the answer \"A gummy bear!\"
|
||
Try to create it using only one line of code."""
|
||
print("¿Que es algo y nada a la vez?\nEl pez")
|
||
|
||
def dos_nums(self):
|
||
"""Ask the user to enter two numbers. Add them together and display
|
||
the answer as The total is [answer]."""
|
||
print("Ingresa dos números")
|
||
num_a = int(input("Primer número: "))
|
||
num_b = int(input("Segundo número: "))
|
||
print(f"{num_a} + {num_b} = {num_a+num_b}")
|
||
|
||
def tres_nums(self):
|
||
"""Ask the user to enter three numbers. Add together the first two
|
||
numbers and then multiply this total by the third. Display the answer as
|
||
The answer is [answer]."""
|
||
print("Ingresa tres números")
|
||
num_a = int(input("Primer número: "))
|
||
num_b = int(input("Segundo número: "))
|
||
num_c = int(input("Tercer número: "))
|
||
res = (num_a+num_b)*num_c
|
||
print(f"({num_a} + {num_b}) x {num_c} = {res}")
|
||
|
||
def pizza(self):
|
||
"""Ask how many slices of pizza the user started with and ask how
|
||
many slices they have eaten. Work out how many slices they have left and
|
||
display the answer in a user-friendly format."""
|
||
num_a = int(input("¿Cuantos pedazos de pizza tenías?: "))
|
||
num_b = int(input("¿Cuantos pedazos de pizza comiste?: "))
|
||
print(f"Aún quedan {num_a-num_b} pedazos")
|
||
|
||
def next_age(self):
|
||
"""Ask the user for their name and their age. Add 1 to their age
|
||
and display the output [Name] next birthday you will be [new age]."""
|
||
name = input("¿Cual es tu nombre?: ")
|
||
age = int(input("¿Que edad tienes?: "))
|
||
print(f"{name} en tu próximo cumpleaños tendrás {age+1}")
|
||
|
||
def a_medias(self):
|
||
"""Ask for the total price of the bill, then ask how many diners
|
||
there are. Divide the total bill by the number of diners and show how
|
||
much each person must pay."""
|
||
total = int(input("¿Cuanto es el total de la cuenta?: "))
|
||
personas = int(input("¿Cuantas personas son?: "))
|
||
print(f"Cada uno debe pagar ${total/personas}")
|
||
|
||
def tiempos(self):
|
||
"""Write a program that will ask for a number of days and then will
|
||
show how many hours, minutes and seconds are in that number of days."""
|
||
dias = int(input("Ingresa una cantidad de días: "))
|
||
horas = dias*24
|
||
minutos = horas*60
|
||
segundos = minutos*60
|
||
print(f"{dias} Días es equivalente a {horas} horas, "
|
||
+f"o {minutos} minutos, o {segundos} segundos.")
|
||
|
||
def pounds(self):
|
||
"""There are 2,204 pounds in a kilogram. Ask the user to enter a
|
||
weight in kilograms and convert it to pounds."""
|
||
peso = int(input("Ingresa un peso en Kilogramos: "))
|
||
libras = peso*2.204
|
||
print(f"{peso} kilogramos equivalen a {libras} libras")
|
||
|
||
def cabe(self):
|
||
"""Task the user to enter a number over 100 and then enter a number
|
||
under 10 and tell them how many times the smaller number goes into the
|
||
larger number in a user-friendly format."""
|
||
num, num2 = 0, 100
|
||
while num <= 100:
|
||
num = int(input("Ingresa un número mayor que 100: "))
|
||
while num2 >= 10:
|
||
num2 = int(input("Ingresa un número menor que 10: "))
|
||
print(f"{num2} cabe {num//num2} veces en {num}")
|