+: basicos 045-051

This commit is contained in:
devfzn 2023-11-10 01:57:44 -03:00
parent 282838a145
commit 5570edbd48
Signed by: devfzn
GPG Key ID: E070ECF4A754FDB1
3 changed files with 136 additions and 2 deletions

View File

@ -3,6 +3,7 @@ from . import basic02 as ex02
from . import basic03 as ex03 from . import basic03 as ex03
from . import basic04 as ex04 from . import basic04 as ex04
from . import basic05 as ex05 from . import basic05 as ex05
from . import basic06 as ex06
from common.common import ( from common.common import (
print_challenges, print_challenges,
user_input, user_input,
@ -28,6 +29,7 @@ def challenges_sublist():
case 5: case 5:
challenges05() challenges05()
case 6: case 6:
challenges06()
pass pass
case 7: case 7:
pass pass
@ -204,3 +206,31 @@ def challenges05():
exit(0) exit(0)
case _: case _:
continue continue
def challenges06():
select_ok = False
while not select_ok:
clear()
i, ex6 = print_challenges(ex06.basics_006)
selection = user_input(i)
match selection:
case 1:
run_func(ex6.over50)
case 2:
run_func(ex6.last_5)
case 3:
run_func(ex6.add_another)
case 4:
run_func(ex6.party)
case 5:
run_func(ex6.compnum)
case 6:
run_func(ex6.between)
case 7:
run_func(ex6.bottles)
case 'v':
return
case 's':
exit(0)
case _:
continue

104
basic/basic06.py Normal file
View File

@ -0,0 +1,104 @@
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}")

View File

@ -29,7 +29,7 @@ def basic_challenges():
clear() clear()
print(content) print(content)
opcs_default() opcs_default()
selection = user_input(5) selection = user_input(6)
match selection: match selection:
case 1: case 1:
basic.challenges01() basic.challenges01()
@ -42,7 +42,7 @@ def basic_challenges():
case 5: case 5:
basic.challenges05() basic.challenges05()
case 6: case 6:
pass basic.challenges06()
case 7: case 7:
pass pass
case 'v': case 'v':