+: intermedios 080-087

This commit is contained in:
devfzn 2023-11-12 23:46:19 -03:00
parent 6994cdcef9
commit 81ec6a7f58
Signed by: devfzn
GPG Key ID: E070ECF4A754FDB1
4 changed files with 118 additions and 33 deletions

View File

@ -29,6 +29,7 @@ de *Nichola Lacey*
## Retos Intermedios
- [069-079](./interm/interm01.py)
- [080-087](./interm/interm02.py)
## Uso

View File

@ -1,4 +1,5 @@
from . import interm01 as ex01
from . import interm02 as ex02
from common.common import (
print_challenges,
user_input,
@ -43,36 +44,36 @@ def challenges01():
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 challenges02():
select_ok = False
while not select_ok:
clear()
i, ex2 = print_challenges(ex02.interm002)
selection = user_input(i)
match selection:
case 1:
run_func(ex2.len_name)
case 2:
run_func(ex2.fav_subj)
case 3:
run_func(ex2.poem)
case 4:
run_func(ex2.while_lower)
case 5:
run_func(ex2.postcode)
case 6:
run_func(ex2.vowels)
case 7:
run_func(ex2.passwrd)
case 8:
run_func(ex2.word_line)
case 'v':
return
case 's':
exit(0)
case _:
continue
#def challenges03():
# select_ok = False
# while not select_ok:

84
interm/interm02.py Normal file
View File

@ -0,0 +1,84 @@
class interm002:
def len_name(self):
"""Ask the user to enter their first name and then display the length of
their first name. Then ask for their surname and display the length of
their surname. Join their first name and surname together with a space
between and display the result. Finally, display the length of their full
name (including the space)."""
name = input("Ingresa tu primer nombre: ")
print(f"Largo: {len(name)}")
surname = input("Ingresa tu apellido: ")
print(f"Largo: {len(surname)}")
full_name = name+' '+surname
print(full_name)
print(f"Largo: {len(full_name)}")
def fav_subj(self):
"""Ask the user to type in their favourite school subject. Display it
with \'-\' after each letter, e.g. S-p-a-n-i-s-h-."""
fav = input("¿Cual es tu asignatura favorita?: ")
print('-'.join(fav))
def poem(self):
"""Show the user a line of text from your favourite poem and ask for a
starting and ending point. Display the characters between those two points."""
poem = "En mi casa hay abustos, y yo quiero a Iris Bustos"
print(poem)
ini = int(input("Ingresa un número inicial: "))
end = int(input("Ingresa un número final: "))
print(poem[ini:end])
def while_lower(self):
"""Ask the user to type in a word in upper case. If they type it in lower
case, ask them to try again. Keep repeating this until they type in a
message all in uppercase."""
while True:
word = input("Ingresa una palabra en mayúsculas: ")
if word.isupper():
break
def postcode(self):
"""Ask the user to type in their postcode. Display the first two letters
in uppercase."""
post = input("Ingresa tu código postal: ")
print(post[0:2].upper()+post[2:])
def vowels(self):
"""Ask the user to type in their name and then tell them how many vowels
are in their name."""
name = input("Ingresa tu nombre: ")
cont = 0
for char in name:
if char in 'AaEeIiOoUu':
cont += 1
print(f"{name} tiene {cont} vocales")
def passwrd(self):
"""Ask the user to enter a new password. Ask them to enter it again. If
the two passwords match, display \"Thank you\". If the letters are
correct but in the wrong case, display the message \"They must be in
the same case\", otherwise display the message \"Incorrect\"."""
pass_1 = input("Ingresa una nueva contraseña: ")
pass_2 = input("Repite tu nueva contraseña: ")
if pass_1 == pass_2:
print("Gracias")
elif pass_1.lower() == pass_2.lower():
print("Se distinguen mayúsculas de minusculas")
else:
print("Las contraseñas no coinciden")
def word_line(self):
"""Ask the user to type in a word and then display it backwards on
separate lines. For instance, if they type in \'Hello\' it should
display as shown below:
Enter a word: Hello
o
l
l
e
H
"""
word = input("Ingresa una palabra: ")
for char in reversed(word):
print(char)

View File

@ -70,13 +70,12 @@ def interm_challenges():
clear()
print(content)
opcs_default(1)
selection = user_input(1)
selection = user_input(2)
match selection:
case 1:
interm.challenges01()
case 2:
#interm.challenges02()
pass
interm.challenges02()
case 3:
#interm.challenges03()
pass