python_by_example/interm/interm02.py
2023-11-12 23:46:19 -03:00

85 lines
3.3 KiB
Python

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)