0
I’m creating a simple script with a def
I printed out a custom menu. The first parameter is the header, followed by the number of items accessible by the menu and finally a third parameter that is unpacked in the function, representing the menu calls.
It’s just a workout, nothing as useful as that, but I feel that what is being delivered is not the most elegant solution, although it simplifies a lot. There may be confusion with the number of items and all the elements typed for the last parameter.
Does anyone have a better idea? Perhaps with a higher or more elegant, functional complexity level, etc.. Or is that what you think the proposed solution would be?
Follows the script:
def personalizado(txt, itens, *chamadas):
print('-=-' * 15)
print(txt.center(45))
print('-=-' * 15)
print()
for c in range(0, itens):
print(f'{c +1} - {chamadas[c]}')
# teste protegido
if __name__ == '__main__':
personalizado('MENU QUALQUER', 6, 'Acessar', 'Visualizar', 'Cadastrar',
'Deletar', 'Reiniciar', 'Exit',)
The result:
-=--=--=--=--=--=--=--=--=--=--=--=--=--=--=-
MENU QUALQUER
-=--=--=--=--=--=--=--=--=--=--=--=--=--=--=-
1 - Acessar
2 - Visualizar
3 - Cadastrar
4 - Deletar
5 - Reiniciar
6 - Exit
Good @Danielmendes, that’s what I was looking for. Avoid redundancies, I ended up observing these changes yesterday. I was looking for a way to printar online too, it was perfect! Thank you!
– Curi