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))