+: intermedios 069-079
This commit is contained in:
parent
f9145a4b56
commit
6994cdcef9
@ -26,6 +26,10 @@ de *Nichola Lacey*
|
|||||||
- [067](./trtl/turtle08.py)
|
- [067](./trtl/turtle08.py)
|
||||||
- [068](./trtl/turtle09.py)
|
- [068](./trtl/turtle09.py)
|
||||||
|
|
||||||
|
## Retos Intermedios
|
||||||
|
|
||||||
|
- [069-079](./interm/interm01.py)
|
||||||
|
|
||||||
## Uso
|
## Uso
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
224
interm/interm.py
Normal file
224
interm/interm.py
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
from . import interm01 as ex01
|
||||||
|
from common.common import (
|
||||||
|
print_challenges,
|
||||||
|
user_input,
|
||||||
|
run_func,
|
||||||
|
clear
|
||||||
|
)
|
||||||
|
|
||||||
|
def challenges01():
|
||||||
|
select_ok = False
|
||||||
|
while not select_ok:
|
||||||
|
clear()
|
||||||
|
i, ex1 = print_challenges(ex01.interm001)
|
||||||
|
selection = user_input(i)
|
||||||
|
match selection:
|
||||||
|
case 1:
|
||||||
|
run_func(ex1.countries)
|
||||||
|
case 2:
|
||||||
|
run_func(ex1.country_pos)
|
||||||
|
case 3:
|
||||||
|
run_func(ex1.two_sports)
|
||||||
|
case 4:
|
||||||
|
run_func(ex1.del_subject)
|
||||||
|
case 5:
|
||||||
|
run_func(ex1.fav_food)
|
||||||
|
case 6:
|
||||||
|
run_func(ex1.ten_colours)
|
||||||
|
case 7:
|
||||||
|
run_func(ex1.four_nums)
|
||||||
|
case 8:
|
||||||
|
run_func(ex1.three_names)
|
||||||
|
case 9:
|
||||||
|
run_func(ex1.uninvite)
|
||||||
|
case 10:
|
||||||
|
run_func(ex1.tv_titles)
|
||||||
|
case 11:
|
||||||
|
run_func(ex1.nums_list)
|
||||||
|
case 'v':
|
||||||
|
return
|
||||||
|
case 's':
|
||||||
|
select_ok = True
|
||||||
|
exit(0)
|
||||||
|
case _:
|
||||||
|
continue
|
||||||
|
|
||||||
|
#def challenges02():
|
||||||
|
# select_ok = False
|
||||||
|
# while not select_ok:
|
||||||
|
# clear()
|
||||||
|
# i, ex2 = print_challenges(ex02.basics_002)
|
||||||
|
# selection = user_input(i)
|
||||||
|
# match selection:
|
||||||
|
# case 1:
|
||||||
|
# run_func(ex2.mayor)
|
||||||
|
# case 2:
|
||||||
|
# run_func(ex2.muy_alto)
|
||||||
|
# case 3:
|
||||||
|
# run_func(ex2.gracias)
|
||||||
|
# case 4:
|
||||||
|
# run_func(ex2.fav_color)
|
||||||
|
# case 5:
|
||||||
|
# run_func(ex2.clima)
|
||||||
|
# case 6:
|
||||||
|
# run_func(ex2.edad_conducir)
|
||||||
|
# case 7:
|
||||||
|
# run_func(ex2.alto_bajo)
|
||||||
|
# case 8:
|
||||||
|
# run_func(ex2.uno_dos_tres)
|
||||||
|
# case 'v':
|
||||||
|
# return
|
||||||
|
# case 's':
|
||||||
|
# exit(0)
|
||||||
|
# case _:
|
||||||
|
# continue
|
||||||
|
#
|
||||||
|
#def challenges03():
|
||||||
|
# select_ok = False
|
||||||
|
# while not select_ok:
|
||||||
|
# clear()
|
||||||
|
# i, ex3 = print_challenges(ex03.basics_003)
|
||||||
|
# selection = user_input(i)
|
||||||
|
# match selection:
|
||||||
|
# case 1:
|
||||||
|
# run_func(ex3.name_length)
|
||||||
|
# case 2:
|
||||||
|
# run_func(ex3.fullname_length)
|
||||||
|
# case 3:
|
||||||
|
# run_func(ex3.full_name_lower)
|
||||||
|
# case 4:
|
||||||
|
# run_func(ex3.nursery)
|
||||||
|
# case 5:
|
||||||
|
# run_func(ex3.any_mayus)
|
||||||
|
# case 6:
|
||||||
|
# run_func(ex3.mambo_name)
|
||||||
|
# case 7:
|
||||||
|
# run_func(ex3.pig_latin)
|
||||||
|
# case 'v':
|
||||||
|
# return
|
||||||
|
# case 's':
|
||||||
|
# exit(0)
|
||||||
|
# case _:
|
||||||
|
# continue
|
||||||
|
#
|
||||||
|
#def challenges04():
|
||||||
|
# select_ok = False
|
||||||
|
# while not select_ok:
|
||||||
|
# clear()
|
||||||
|
# i, ex4 = print_challenges(ex04.basics_004)
|
||||||
|
# selection = user_input(i)
|
||||||
|
# match selection:
|
||||||
|
# case 1:
|
||||||
|
# run_func(ex4.decims)
|
||||||
|
# case 2:
|
||||||
|
# run_func(ex4.decims_round)
|
||||||
|
# case 3:
|
||||||
|
# run_func(ex4.square_root)
|
||||||
|
# case 4:
|
||||||
|
# run_func(ex4.pi_round)
|
||||||
|
# case 5:
|
||||||
|
# run_func(ex4.circle_area)
|
||||||
|
# case 6:
|
||||||
|
# run_func(ex4.cyl_vol)
|
||||||
|
# case 7:
|
||||||
|
# run_func(ex4.friendly_div)
|
||||||
|
# case 8:
|
||||||
|
# run_func(ex4.circ_trian)
|
||||||
|
# case 'v':
|
||||||
|
# return
|
||||||
|
# case 's':
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
#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
|
||||||
|
#
|
||||||
|
#def challenges07():
|
||||||
|
# select_ok = False
|
||||||
|
# while not select_ok:
|
||||||
|
# clear()
|
||||||
|
# i, ex7 = print_challenges(ex07.basics_007)
|
||||||
|
# selection = user_input(i)
|
||||||
|
# match selection:
|
||||||
|
# case 1:
|
||||||
|
# run_func(ex7.rand_range)
|
||||||
|
# case 2:
|
||||||
|
# run_func(ex7.rand_choice)
|
||||||
|
# case 3:
|
||||||
|
# run_func(ex7.rand_game)
|
||||||
|
# case 4:
|
||||||
|
# run_func(ex7.rand_pick)
|
||||||
|
# case 5:
|
||||||
|
# run_func(ex7.rand_10)
|
||||||
|
# case 6:
|
||||||
|
# run_func(ex7.rand_10_upgrade)
|
||||||
|
# case 7:
|
||||||
|
# run_func(ex7.rand_quiz)
|
||||||
|
# case 8:
|
||||||
|
# run_func(ex7.rand_color)
|
||||||
|
# case 'v':
|
||||||
|
# return
|
||||||
|
# case 's':
|
||||||
|
# exit(0)
|
||||||
|
# case _:
|
||||||
|
# continue
|
171
interm/interm01.py
Normal file
171
interm/interm01.py
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
class interm001:
|
||||||
|
|
||||||
|
def countries(self):
|
||||||
|
"""Create a tuple containing the names of five countries and display the
|
||||||
|
whole tuple. Ask the user to enter one of the countries that have been
|
||||||
|
shown to them and then display the index number (i.e. position in the
|
||||||
|
list) of that item in the tuple."""
|
||||||
|
counties = ('Peru', 'Bolivia', 'Brazil', 'Chile', 'Argentina')
|
||||||
|
print('Paises:', ', '.join(counties))
|
||||||
|
sel = input("Ingresa uno de los países mostrados: ")
|
||||||
|
print(f"Indice: {counties.index(sel)}")
|
||||||
|
|
||||||
|
def country_pos(self):
|
||||||
|
"""Add to program 069 to ask the user to enter a number and display the
|
||||||
|
country in that position."""
|
||||||
|
counties = ('Peru', 'Bolivia', 'Brazil', 'Chile', 'Argentina')
|
||||||
|
print('Indice | Pais\n------------------')
|
||||||
|
for i,c in enumerate(counties):
|
||||||
|
print(f" {i} | {c}")
|
||||||
|
num = int(input("\nIngresa un indice: "))
|
||||||
|
if num < len(counties):
|
||||||
|
print(counties[num])
|
||||||
|
else:
|
||||||
|
print(f"El índice {num} no existe")
|
||||||
|
|
||||||
|
def two_sports(self):
|
||||||
|
"""Create a list of two sports. Ask the user what their favourite sport
|
||||||
|
is and add this to the end of the list. Sort the list and display it."""
|
||||||
|
sports = ['Kaiju Big Battle', 'Cheese rolling ']
|
||||||
|
fav = input("Ingresa tu deporte favorito: ")
|
||||||
|
sports.append(fav)
|
||||||
|
sports.sort()
|
||||||
|
print("Deportes: ", ", ".join(sports))
|
||||||
|
|
||||||
|
def del_subject(self):
|
||||||
|
"""Create a list of six school subjects. Ask the user which of these
|
||||||
|
subjects they don’t like. Delete the subject they have chosen from the
|
||||||
|
list before you display the list again."""
|
||||||
|
subjs = ['Redes', 'POO', 'SQL', 'Algoritmos', 'Hardware']
|
||||||
|
print("Materias: ", ", ".join(subjs))
|
||||||
|
sel = input("¿Cual de estas materias no te agrada?: ")
|
||||||
|
if sel in subjs:
|
||||||
|
subjs.remove(sel)
|
||||||
|
else:
|
||||||
|
print(f"{sel} no está en la lista")
|
||||||
|
print("Materias: ", ", ".join(subjs))
|
||||||
|
|
||||||
|
def fav_food(self):
|
||||||
|
"""Ask the user to enter four of their favourite foods and store them in
|
||||||
|
a dictionary so that they are indexed with numbers starting from 1.
|
||||||
|
Display the dictionary in full, showing the index number and the item.
|
||||||
|
Ask them which they want to get rid of and remove it from the list.
|
||||||
|
Sort the remaining data and display the dictionary."""
|
||||||
|
favs = {}
|
||||||
|
print("Ingresa 4 platos/comidas favoritas")
|
||||||
|
for i in range(1,5):
|
||||||
|
fav = input(f"Ingresa tu comida favorita para la posición {i}: ")
|
||||||
|
favs[i] = fav
|
||||||
|
print(*[str(key) + ':' + str(value) for key,value in favs.items()])
|
||||||
|
sel = int(input("Ingresa el indice del menos favorito: "))
|
||||||
|
favs.pop(sel)
|
||||||
|
print(', '.join(sorted(favs.values())))
|
||||||
|
|
||||||
|
def ten_colours(self):
|
||||||
|
"""Enter a list of ten colours. Ask the user for a starting number
|
||||||
|
between 0 and 4 and an end number between 5 and 9. Display the list for
|
||||||
|
those colours between the start and end numbers the user input."""
|
||||||
|
colors = ['Amarillo', 'Azul', 'Celeste', 'Blanco', 'Magenta',
|
||||||
|
'Naranjo', 'Negro', 'Rojo', 'Rosado', 'Verde']
|
||||||
|
num_1 = int(input("Ingresa un número entre 0 y 4: "))
|
||||||
|
num_2 = int(input("Ingresa un número entre 5 y 9: "))
|
||||||
|
print(', '.join(colors[num_1:num_2+1]))
|
||||||
|
|
||||||
|
def four_nums(self):
|
||||||
|
"""Create a list of four three-digit numbers. Display the list to the
|
||||||
|
user, showing each item from the list on a separate line. Ask the user
|
||||||
|
to enter a three-digit number. If the number they have typed in matches
|
||||||
|
one in the list, display the position of that number in the list,
|
||||||
|
otherwise display the message \"That is not in the list\"."""
|
||||||
|
nums = [475, 912, 661, 101]
|
||||||
|
print(*[str(value)+'\n' for value in nums])
|
||||||
|
sel = int(input("Ingresa un número de 3 digitos: "))
|
||||||
|
if sel in nums:
|
||||||
|
print(f"{sel} está en el índice: {nums.index(sel)}")
|
||||||
|
else:
|
||||||
|
print(f"{sel} no está en la lista")
|
||||||
|
|
||||||
|
|
||||||
|
def three_names(self):
|
||||||
|
"""Ask the user to enter the names of three people they want to invite
|
||||||
|
to a party and store them in a list. After they have entered all three
|
||||||
|
names, ask them if they want to add another. If they do, allow them to
|
||||||
|
add more names until they answer \"no\". When they answer \"no\",
|
||||||
|
display how many people they have invited to the party."""
|
||||||
|
names = []
|
||||||
|
for i in range(1,4):
|
||||||
|
name = input(f"Ingresa el nombre nro. {i}: ")
|
||||||
|
names.append(name)
|
||||||
|
while True:
|
||||||
|
ask = input("¿Deseas agregar mas personas? (si|no): ").lower()
|
||||||
|
if ask == 'si':
|
||||||
|
name = input(f"Ingresa el nombre nro. {len(names)+1}: ")
|
||||||
|
names.append(name)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
print(f"Has invitado {len(names)} personas")
|
||||||
|
|
||||||
|
|
||||||
|
def uninvite(self):
|
||||||
|
"""Change program 076 so that once the user has completed their list of
|
||||||
|
names, display the full list and ask them to type in one of the names on
|
||||||
|
the list. Display the position of that name in the list. Ask the user if
|
||||||
|
they still want that person to come to the party. If they answer \"no\",
|
||||||
|
delete that entry from the list and display the list again."""
|
||||||
|
names = []
|
||||||
|
for i in range(1,4):
|
||||||
|
name = input(f"Ingresa el nombre nro. {i}: ")
|
||||||
|
names.append(name)
|
||||||
|
while True:
|
||||||
|
ask = input("¿Deseas agregar mas personas? (s|n): ").lower()
|
||||||
|
if ask == 's':
|
||||||
|
name = input(f"Ingresa el nombre nro. {len(names)+1}: ")
|
||||||
|
names.append(name)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
print("\nLista de invitados:")
|
||||||
|
for name in names:
|
||||||
|
print(' '+name)
|
||||||
|
name = input("\nIngresa el nombre de un invitado: ")
|
||||||
|
if name in names:
|
||||||
|
print(f"Invitado {name}, en la posición {names.index(name)}")
|
||||||
|
resp = input("¿Quieres mantener la invitación? (si|no): ").lower()
|
||||||
|
if resp == 'no':
|
||||||
|
names.remove(name)
|
||||||
|
print("Lista de invitados:")
|
||||||
|
for name in names:
|
||||||
|
print(' '+name)
|
||||||
|
else:
|
||||||
|
print(f"{name} no está en la lista de invitados")
|
||||||
|
|
||||||
|
def tv_titles(self):
|
||||||
|
"""Create a list containing the titles of four TV programmes and display
|
||||||
|
them on separate lines. Ask the user to enter another show and a position
|
||||||
|
they want it inserted into the list. Display the list again, showing all
|
||||||
|
five TV programmes in their new positions."""
|
||||||
|
tv = ['Rick & Morty', 'South Park', 'American Dad', 'Family Guy']
|
||||||
|
for show in tv:
|
||||||
|
print(show)
|
||||||
|
new_show = input("\nIngresa una serie: ")
|
||||||
|
new_pos = int(input("Ingresa una posición: "))
|
||||||
|
tv.insert(new_pos, new_show)
|
||||||
|
for show in tv:
|
||||||
|
print(show)
|
||||||
|
|
||||||
|
def nums_list(self):
|
||||||
|
"""Create an empty list called \"nums\". Ask the user to enter numbers.
|
||||||
|
After each number is entered, add it to the end of the nums list and
|
||||||
|
display the list. Once they have entered three numbers, ask them if they
|
||||||
|
still want the last number they entered saved. If they say \"no\",
|
||||||
|
remove the last item from the list. Display the list of numbers."""
|
||||||
|
nums = []
|
||||||
|
while True:
|
||||||
|
num = input("Ingresa un número: ")
|
||||||
|
nums.append(num)
|
||||||
|
print('Lista:' ,', '.join(nums))
|
||||||
|
if len(nums) >= 3:
|
||||||
|
resp = input("¿Deseas mantener el último número agregado? (si|no): ").lower()
|
||||||
|
if resp == 'no':
|
||||||
|
nums.pop()
|
||||||
|
break
|
||||||
|
print('Lista:' ,', '.join(nums))
|
37
main.py
37
main.py
@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
from basic import basic
|
from basic import basic
|
||||||
from trtl import trtl
|
from trtl import trtl
|
||||||
|
from interm import interm
|
||||||
from common.common import clear, user_input, opcs_default
|
from common.common import clear, user_input, opcs_default
|
||||||
|
|
||||||
def toc():
|
def toc():
|
||||||
content="""\tContenido\n
|
content="""\tContenido\n
|
||||||
1) Basicos 001-059
|
1) Basicos 001-059
|
||||||
2) Turtle 060-068
|
2) Turtle 060-068
|
||||||
3) Intermedio 069-123
|
3) Intermedios 069-123
|
||||||
4) Tkinter 124-138
|
4) Tkinter 124-138
|
||||||
5) SQLite 139-145
|
5) SQLite 139-145
|
||||||
...
|
...
|
||||||
@ -64,7 +65,39 @@ def interm_challenges():
|
|||||||
6) Interm 111-117
|
6) Interm 111-117
|
||||||
7) Interm 118-123
|
7) Interm 118-123
|
||||||
"""
|
"""
|
||||||
print(content)
|
select_ok = False
|
||||||
|
while not select_ok:
|
||||||
|
clear()
|
||||||
|
print(content)
|
||||||
|
opcs_default(1)
|
||||||
|
selection = user_input(1)
|
||||||
|
match selection:
|
||||||
|
case 1:
|
||||||
|
interm.challenges01()
|
||||||
|
case 2:
|
||||||
|
#interm.challenges02()
|
||||||
|
pass
|
||||||
|
case 3:
|
||||||
|
#interm.challenges03()
|
||||||
|
pass
|
||||||
|
case 4:
|
||||||
|
#interm.challenges04()
|
||||||
|
pass
|
||||||
|
case 5:
|
||||||
|
#interm.challenges05()
|
||||||
|
pass
|
||||||
|
case 6:
|
||||||
|
#interm.challenges06()
|
||||||
|
pass
|
||||||
|
case 7:
|
||||||
|
#interm.challenges07()
|
||||||
|
pass
|
||||||
|
case 'v':
|
||||||
|
return
|
||||||
|
case 's':
|
||||||
|
exit(0)
|
||||||
|
case _:
|
||||||
|
continue
|
||||||
|
|
||||||
def tkinter_challenges():
|
def tkinter_challenges():
|
||||||
content = """
|
content = """
|
||||||
|
Loading…
Reference in New Issue
Block a user