105 lines
4.8 KiB
Python
105 lines
4.8 KiB
Python
class basics_006:
|
|
|
|
def over50(self):
|
|
"""Set the total to 0 to start with. While the total is 50 or less, ask
|
|
the user to input a number. Add that number to the total and print the
|
|
message \"The total is… [total]\". Stop the loop when the total is over
|
|
50"""
|
|
total = 0
|
|
while total <= 50:
|
|
num = int(input("Ingresa un número: "))
|
|
total += num
|
|
print(f"El total es {total}")
|
|
|
|
def last_5(self):
|
|
"""Ask the user to enter a number. Keep asking until they enter a value
|
|
over 5 and then display the message \"The last number you entered was a
|
|
[number]\" and stop the program."""
|
|
num = 0
|
|
while num <= 5:
|
|
num = int(input("Ingresa un número: "))
|
|
print(f"El último número ingresado fue [{num}]")
|
|
|
|
def add_another(self):
|
|
"""Ask the user to enter a number and then enter another number. Add
|
|
these two numbers together and then ask if they want to add another
|
|
number. If they enter \"y\", ask them to enter another number and keep
|
|
adding numbers until they do not answer \"y\". Once the loop has
|
|
stopped, display the total."""
|
|
resp = 's'
|
|
num_1 = int(input("Ingresa un número: "))
|
|
while resp == 's':
|
|
num_2 = int(input("Ingresa otro número: "))
|
|
num_1 += num_2
|
|
resp = input("Deseas agregar otro número? (s|n): ").lower()
|
|
print(f"El total es {num_1}")
|
|
|
|
def party(self):
|
|
"""Ask for the name of somebody the user wants to invite to a party.
|
|
After this, display the message \"[name] has now been invited\" and add
|
|
1 to the count. Then ask if they want to invite somebody else. Keep
|
|
repeating this until they no longer want to invite anyone else to the
|
|
party and then display how many people they have coming to the party."""
|
|
cont = 's'
|
|
guests = 0
|
|
while cont == 's':
|
|
name = input("Ingresa el nombre de quien quieras invitar: ")
|
|
print(f"{name} ha sido invitado")
|
|
guests += 1
|
|
cont = input("Deseas invitar a otra persona? (s|n): ")
|
|
print(f"Has invitado a {guests} persona(s)")
|
|
|
|
def compnum(self):
|
|
"""Create a variable called compnum and set the value to 50. Ask the
|
|
user to enter a number. While their guess is not the same as the compnum
|
|
value, tell them if their guess is too low or too high and ask them to
|
|
have another guess. If they enter the same value as compnum, display
|
|
the message \"Well done, you took [count] attempts\"."""
|
|
compnum = 50
|
|
count = 0
|
|
guess = 0
|
|
while guess != compnum:
|
|
guess = int(input("Ingresa un número: "))
|
|
count += 1
|
|
if guess < compnum:
|
|
print("Muy bajo")
|
|
elif guess > compnum:
|
|
print("Muy alto")
|
|
print(f"Bien hecho, solo te tomó {count} intentos")
|
|
|
|
def between(self):
|
|
"""Ask the user to enter a number between 10 and 20. If they enter a
|
|
value under 10, display the message \"Too low\" and ask them to try
|
|
again. If they enter a value above 20, display the message \"Too high\"
|
|
and ask them to try again. Keep repeating this until they enter a value
|
|
that is between 10 and 20 and then display the message \"Thank you\"."""
|
|
num = int(input("Ingresa un número entre 10 y 20: "))
|
|
while (num < 10 or num > 20):
|
|
if num < 10:
|
|
print("Muy Bajo")
|
|
elif num > 20:
|
|
print("Muy Alto")
|
|
num = int(input("Intenta nuevamente: "))
|
|
print("Gracias")
|
|
|
|
def bottles(self):
|
|
"""Using the song \"5 green bottles\", display the lines \"There are
|
|
[num] green bottles hanging on the wall, [num] green bottles hanging on
|
|
the wall, and if 1 green bottle should accidentally fall\". Then ask the
|
|
question \"how many green bottles will be hanging on the wall?\" If the
|
|
user answers correctly, display the message \"There will be [num] green
|
|
bottles hanging on the wall\". If they answer incorrectly, display the
|
|
message \"No, try again\" until they get it right. When the number of
|
|
green bottles gets down to 0, display the message \"There are no more
|
|
green bottles hanging on the wall\"."""
|
|
action = [ 'al cerro', 'de viejuno', 'de tos', 'en tren', 'para el campo']
|
|
num = 5
|
|
while num > 0:
|
|
print(f"Yo tenia {num} perritos! Yo tenia {num} perritos!")
|
|
num -= 1
|
|
print(f"Uno se fue {action[num]}, no me quedan mas que \'?\'")
|
|
resp = int(input("¿Cuantos perritos quedan?: "))
|
|
while resp != num:
|
|
resp = int(input("Intenta nuevamente: "))
|
|
print(f"Uno se fue {action[num]}, no me quedan mas que {resp}")
|