Although the other answer produces the expected result, I do not think it is a good solution, since if you need to add more options nicknames, you will have to add other conditions in the structure. Not good for application maintenance.
The solution I propose is to store the nicknames together with their sentences in a dictionary:
NICKNAMES = {
'Phil': 'Player encrenqueiro, nível de habilidades: razoável.',
'Knuckles': 'Ótimo player, muito cooperativo, nível de habilidades: alta!',
'Bubble': 'Considerado um dos melhores players no game, extremamente flexível e\n adaptável ao jogo de seu parceiro, nível de habilidades: altíssima!',
'Woss': 'Pica das galáxias. Com certeza o melhor! Boa escolha, nível de habilidades: mais que 8000!'
}
And, already predicting that the user can enter another option other than these, set a message to display by default:
DEFAULT = 'Huum, não sei o que dizer sobre esse player :('
To read the user input, use an infinite loop until it confirms the nick that he wishes to use.
while True:
print("Qual nick gostaria de utilizar?")
print("Que tal essas opções:", list(NICKNAMES.keys()), '?')
nick = input("Nick: ")
print(NICKNAMES.get(nick, DEFAULT))
confirm = input('Gostaria de manter esse nick? [S/n] ')
if confirm in ['S', 's', '']:
break
else:
print()
print('Ok, seu nick será {}'.format(nick))
See working on Repl.it
So if you need to define others nicknames, just add in the dictionary, which could be a structure stored in a database or even in a JSON file, for example.
A possible exit from this code would be:
Qual nick gostaria de utilizar?
Que tal essas opções: ['Phil', 'Knuckles', 'Bubble', 'Woss'] ?
Nick: Phil
Player encrenqueiro, nível de habilidades: razoável.
Gostaria de manter esse nick? [S/n] n
Qual nick gostaria de utilizar?
Que tal essas opções: ['Phil', 'Knuckles', 'Bubble', 'Woss'] ?
Nick: Knuckles
Ótimo player, muito cooperativo, nível de habilidades: alta!
Gostaria de manter esse nick? [S/n] n
Qual nick gostaria de utilizar?
Que tal essas opções: ['Phil', 'Knuckles', 'Bubble', 'Woss'] ?
Nick: Bubble
Considerado um dos melhores players no game, extremamente flexível e
adaptável ao jogo de seu parceiro, nível de habilidades: altíssima!
Gostaria de manter esse nick? [S/n] n
Qual nick gostaria de utilizar?
Que tal essas opções: ['Phil', 'Knuckles', 'Bubble', 'Woss'] ?
Nick: Horacio
Huum, não sei o que dizer sobre esse player :(
Gostaria de manter esse nick? [S/n] n
Qual nick gostaria de utilizar?
Que tal essas opções: ['Phil', 'Knuckles', 'Bubble', 'Woss'] ?
Nick: Woss
Pica das galáxias. Com certeza o melhor! Boa escolha, nível de habilidades: mais que 8000!
Gostaria de manter esse nick? [S/n] s
Ok, seu nick será Woss
The ideal would be for you to post the code in text instead of image. On your question, you can make a repeat loop, or repeat the snippet that reads the input once for each if instead of Elif
– Math
Could you demonstrate that? I only know how to use while and again with some message, purely this,I don’t know how to use after the user replies something,e yes,next post the code instead of the image,.
– ScriptKiddie
EDIT: text code now.
– ScriptKiddie
Have you solved it yet? With a while cycle you do it
– Miguel
Not yet Miguel, I need a small demonstration, if possible, I understand better by looking,I looked a lot before coming to ask here,but all I think is how to use the while and for PURELY(only this),and my goal is to repeat the question after the user has received an answer to the nick he typed,example: type a nickname: strawberry/answer: strawberry is a great player,:
– ScriptKiddie
https://wiki.python.org/moin/WhileLoop
– Leonardo Alves Machado
Leonardo Alves Machado Do you really think I didn’t read about while/for before I came here to ask? as I said,I know how to use them purely,and not put them to give a particular answer,for every nick the user types,and after that ask to type in the next player,and so on,understand? is confusing to explain, haha,.
– ScriptKiddie
Take a look at my answer, it is not to show again the phrase if it has already been typed?
– Laerte