+: basicos 035-044

This commit is contained in:
devfzn 2023-11-09 20:37:02 -03:00
parent fd9f7f83d0
commit 282838a145
Signed by: devfzn
GPG Key ID: E070ECF4A754FDB1
3 changed files with 154 additions and 10 deletions

View File

@ -2,6 +2,7 @@ from . import basic01 as ex01
from . import basic02 as ex02
from . import basic03 as ex03
from . import basic04 as ex04
from . import basic05 as ex05
from common.common import (
print_challenges,
user_input,
@ -25,7 +26,7 @@ def challenges_sublist():
case 4:
challenges04()
case 5:
pass
challenges05()
case 6:
pass
case 7:
@ -169,3 +170,37 @@ def challenges04():
exit(0)
case _:
continue
def challenges05():
select_ok = False
while not select_ok:
clear()
i, ex5 = print_challenges(ex05.basics_005)
selection = user_input(i)
match selection:
case 1:
run_func(ex5.name_three)
case 2:
run_func(ex5.name_num)
case 3:
run_func(ex5.name_nl)
case 4:
run_func(ex5.name_nl_num)
case 5:
run_func(ex5.times_table)
case 6:
run_func(ex5.count_down)
case 7:
run_func(ex5.mambo_name)
case 8:
run_func(ex5.may_add)
case 9:
run_func(ex5.up_or_down)
case 10:
run_func(ex5.guests)
case 'v':
return
case 's':
exit(0)
case _:
continue

109
basic/basic05.py Normal file
View File

@ -0,0 +1,109 @@
class basics_005:
def name_three(self):
"Ask the user to enter their name and then display their name three times."
name = input("Ingresa tu nombre: ")
for _ in range(3):
print(name)
def name_num(self):
"""Alter program 035 so that it will ask the user to enter their name and
a number and then display their name that number of times."""
name = input("Ingresa tu nombre: ")
num = int(input("Ingresa un número: "))
for _ in range(num):
print(name)
def name_nl(self):
"""Ask the user to enter their name and display each letter in their name
on a separate line."""
name = input("Ingresa tu nombre: ")
for char in name:
print(char)
def name_nl_num(self):
"""Change program 037 to also ask for a number. Display their name (one
letter at a time on each line) and repeat this for the number of times
they entered."""
name = input("Ingresa tu nombre: ")
num = int(input("Ingresa un número: "))
for _ in range(num):
for char in name:
print(char)
def times_table(self):
"""Ask the user to enter a number between 1 and 12 and then display the
times table for that number."""
num = int(input("Ingresa un número entre 1 y 12: "))
for i in range(1,13):
res = num*i
print(f'{i} x {num} = {res}')
def count_down(self):
"""Ask for a number below 50 and then count down from 50 to that number,
making sure you show the number they entered in the output."""
from time import sleep
num = int(input("Ingresa un número inferior a 50: "))
for i in range(50, num-1, -1):
print(f'{num}: {i}')
sleep(0.05)
def mambo_name(self):
"""Ask the user to enter their name and a number. If the number is less
than 10, then display their name that number of times; otherwise display
the message \"Too high\" three times."""
name = input("Ingresa tu nombre: ")
num = int(input("Ingresa un número: "))
if num < 10:
for _ in range(num):
print(name)
else:
for _ in range(3):
print("Muy alto")
def may_add(self):
"""Set a variable called total to 0. Ask the user to enter five numbers
and after each input ask them if they want that number included. If
they do, then add the number to the total. If they do not want it
included, dont add it to the total. After they have entered all five
numbers, display the total."""
total = 0
for _ in range(5):
tmp = int(input("Ingresa un número: "))
res = input("¿Quieres agregarlo al total? [s|n]").lower()
if res == 's':
total += tmp
print(f"El total es: {total}")
def up_or_down(self):
"""Ask which direction the user wants to count (up or down). If they
select up, then ask them for the top number and then count from 1 to
that number. If they select down, ask them to enter a number below 20
and then count down from 20 to that number. If they entered something
other than up or down, display the message \"I dont understand\"."""
from time import sleep
toward = input("¿Prefieres contar hacia ARRIBA o hacia ABAJO?: ").lower()
if toward == 'arriba':
num = int(input("Ingresa un número límite: "))
for i in range(1, num+1):
print(i)
elif toward == 'abajo':
num = int(input("Ingresa un número menor a 20: "))
for i in range(20, num-1, -1):
print(i)
sleep(0.05)
else:
print("No te entiendo")
def guests(self):
"""Ask how many people the user wants to invite to a party. If they enter
a number below 10, ask for the names and after each name display \"[name]
has been invited\". If they enter a number which is 10 or higher, display
the message \"Too many people\"."""
num = int(input("¿Cuantas personas quieres invitar a la fiesta?: "))
if num < 10:
for _ in range(num):
name = input("Ingresa el nombre del invitado: ")
print(f'{name} ha sido invitado')
else:
print("Demasiadas personas")

18
main.py
View File

@ -16,13 +16,13 @@ def toc():
def basic_challenges():
content = """
1) Basics 001-011
2) Basics 012-019
3) Basics 020-026
4) Basics 027-034
5) Basics 035-044
6) Basics 045-051
7) Basics 052-059
1) Basicos 001-011
2) Basicos 012-019
3) Basicos 020-026
4) Basicos 027-034
5) Basicos 035-044
6) Basicos 045-051
7) Basicos 052-059
"""
select_ok = False
while not select_ok:
@ -40,7 +40,7 @@ def basic_challenges():
case 4:
basic.challenges04()
case 5:
pass
basic.challenges05()
case 6:
pass
case 7:
@ -86,7 +86,7 @@ def main():
clear()
print(header)
toc()
selection = user_input(5)
selection = user_input(3)
match selection:
case 1:
basic_challenges()