class interm004: def two_d(self): """Create the following using a simple 2D list using the standard Python indexing - 0 1 2 ━━━━━━━━━━━━━━━ 0 2 5 8 1 3 7 4 2 1 6 9 3 4 2 0""" bidims = [[2,5,8],[3,7,4],[1,6,9],[4,2,0]] print(" | 0 | 1 | 2 |\n━━━━━━━━━━━━━━━") for i in range(len(bidims)): print(i, '|', ' | '.join(map(str, bidims[i])), end=' |\n') def sel_row_col(self): """Using the 2D list from program 096, ask the user to select a row and a column and display that value.""" bidims = [[2,5,8],[3,7,4],[1,6,9],[4,2,0]] print(" | 0 | 1 | 2 |\n━━━━━━━━━━━━━━━") for i in range(len(bidims)): print(i, '|', ' | '.join(map(str, bidims[i])), end=' |\n') sel_r = int(input("\nSelecciona una fila: ")) sel_c = int(input("Selecciona una columna: ")) if sel_r < len(bidims) and sel_c < len(bidims[0]): print(bidims[sel_r][sel_c]) else: print("Fuera de rango") def sel_row(self): """Using the 2D list from program 096, ask the user which row they would like displayed and display just that row. Ask them to enter a new value and add it to the end of the row and display the row again.""" bidims = [[2,5,8],[3,7,4],[1,6,9],[4,2,0]] print(" | 0 | 1 | 2 |\n━━━━━━━━━━━━━━━") for i in range(len(bidims)): print(i, '|', ' | '.join(map(str, bidims[i])), end=' |\n') sel_r = int(input("\nSelecciona una fila: ")) if sel_r < len(bidims): print(bidims[sel_r]) new_value = int(input("Ingresa un valor: ")) bidims[sel_r][-1] = new_value print(bidims[sel_r]) else: print("Fuera de rango") def change_val(self): """Change your previous program to ask the user which row they want displayed. Display that row. Ask which column in that row they want displayed and display the value that is held there. Ask the user if they want to change the value. If they do, ask for a new value and change the data. Finally, display the whole row again.""" bidims = [[2,5,8],[3,7,4],[1,6,9],[4,2,0]] print(" | 0 | 1 | 2 |\n━━━━━━━━━━━━━━━") for i in range(len(bidims)): print(i, '|', ' | '.join(map(str, bidims[i])), end=' |\n') sel_r = int(input("\nSelecciona una fila: ")) if sel_r < len(bidims): print(bidims[sel_r]) sel_c = int(input("Selecciona una columna: ")) if sel_c < len(bidims[0]): print(bidims[sel_r][sel_c]) resp = input("¿Quieres cambiar este valor? (s|n): ").lower() if resp == 's': print(bidims[sel_r]) new_value = int(input("Ingresa un valor: ")) bidims[sel_r][sel_c] = new_value else: print("Fuera de rango") else: print("Fuera de rango") print(bidims[sel_r]) def bidims_dict(self): """Create the following using a 2D dictionary showing the sales each person has made in the different geographical regions: - N S E W ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ John 3056 8463 8441 2694 Tom 4832 6786 4737 3612 Anne 5239 4802 5820 1859 Fiona 3904 3645 8821 2451 """ bidict = {"John":{'N':3056, 'S':8463, 'E':8441, 'W':2694}, "Tom":{'N':4832, 'S':6786, 'E':4737, 'W':3612}, "Anne":{'N':5239, 'S':4802, 'E':5820, 'W':1859}, "Fiona":{'N':3904, 'S':3645, 'E':8821, 'W':2451}} print(" | N | S | E | W |") print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━") for name in bidict: print(name.rjust(5), '|', ' | '.join(map(str, bidict[name].values())), end=' |\n') def bidict(self): """Using program 100, ask the user for a name and a region. Display the relevant data. Ask the user for the name and region of data they want to change and allow them to make the alteration to the sales figure. Display the sales for all regions for the name they choose.""" bidict = {"John":{'N':3056, 'S':8463, 'E':8441, 'W':2694}, "Tom":{'N':4832, 'S':6786, 'E':4737, 'W':3612}, "Anne":{'N':5239, 'S':4802, 'E':5820, 'W':1859}, "Fiona":{'N':3904, 'S':3645, 'E':8821, 'W':2451}} self.bidims_dict() name = input("\nIngresa un nombre del cuadro: ").title() reg = input("Ingresa un sector: ").upper() print(bidict[name][reg]) new_val = int(input("Ingresa el nuevo valor: ")) bidict[name][reg] = new_val print(', '.join(map(str, bidict[name].values()))) def user_data(self): """Ask the user to enter the name, age and shoe size for four people. Ask for the name of one of the people in the list and display their age and shoe size.""" data = {} print("Se solicitarán 4 usuarios y su respectivos datos") for i in range(4): name = input(f"{i+1} Ingresa un nombre: ").capitalize() age = int(input(f"Ingresa la edad de {name}: ")) shoe = int(input(f"Ingresa cuanto calza {name}: ")) data[name]={"Edad":age, "Calzado":shoe} name = input("Ingresa uno de los nombres agregados anteriormente: ").capitalize() print(*[str(k) + ':' + str(v) for k,v in data[name].items()]) def dict_show_filter(self): """Adapt program 102 to display the names and ages of all the people in the list but do not show their shoe size.""" data = {} print("Se solicitarán 4 usuarios y su respectivos datos") for i in range(4): name = input(f"{i+1} Ingresa un nombre: ").capitalize() age = int(input(f"Ingresa la edad de {name}: ")) shoe = int(input(f"Ingresa cuanto calza {name}: ")) data[name]={"Edad":age, "Calzado":shoe} for name in data.keys(): print("Nombre:", name, "Edad:", data[name]["Edad"]) def dict_remove(self): """After gathering the four names, ages and shoe sizes, ask the user to enter the name of the person they want to remove from the list. Delete this row from the data and display the other rows on separate lines.""" data = {} print("Se solicitarán 4 usuarios y su respectivos datos") for i in range(4): name = input(f"{i+1} Ingresa un nombre: ").capitalize() age = int(input(f"Ingresa la edad de {name}: ")) shoe = int(input(f"Ingresa cuanto calza {name}: ")) data[name]={"Edad":age, "Calzado":shoe} for name in data.keys(): print("Nombre:", name, "Edad:", data[name]["Edad"], "Talla:", data[name]["Calzado"]) name = input("Ingresa el nombre del usuario a borrar: ").capitalize() data.pop(name) for name in data.keys(): print("Nombre:", name, "Edad:", data[name]["Edad"], "Talla:", data[name]["Calzado"])