In my program, I have a dictionary called the_dictionary_list
described as follows:
the_dictionary_list = {'Color': ['Amarillo.png', 'Blanco.png', 'Rojirosado.png', 'Turquesa.png', 'Verde_oscuro.png', 'Zapote.png'], 'Cuerpo': ['Cuerpo_cangrejo.png'], 'Fondo': ['Oceano.png'], 'Ojos': ['Antenas.png', 'Pico.png', 'Verticales.png'], 'Pinzas': ['Pinzitas.png', 'Pinzotas.png', 'Pinzota_pinzita.png'], 'Puas': ['Arena.png', 'Marron.png', 'Purpura.png', 'Verde.png']}
Now, the user will be asked to decide if he wants to add a "None" item to an array in the dictionary or not, he will then be asked which one of the available dictionary keys will be updated the with the None
text, then the user enters the name of the key as input, the input can be within single quotation marks or not as long as it's a valid key, if the input doesn't exist in the dictionary he will have to enter one again, until he doesn't want to update one of the available dictionary keys anymore:
entrada = input('All right, do you want to add a "None" item to an array in the dictionary? (y/n):')
while True:
if entrada == 'y':
while True:
key_entrada = input('Cool, now tell me at which key do you want me to add a "None" item? Type only a valid key name:')
if key_entrada.startswith("'") & key_entrada.endswith("'"):
if key_entrada in the_dictionary_list:
the_dictionary_list[key_entrada].insert(0, 'None')
entrada = input('Do you want to add another one? (y/n):')
if entrada == 'n':
print('ta weno')
break
if entrada == 'y':
break
else:
break
else:
key_entrada = input('That input does not exist in the dictionary, try again, Type only a valid key name:')
else:
print('you did not put single quotation marks, let me add them to your input')
comillas = str("'") key_entrada str("'")
if comillas in the_dictionary_list:
the_dictionary_list[comillas].insert(0, 'None')
entrada = input('Do you want to add another one? (y/n):')
if entrada == 'n':
print('ta weno')
break
if entrada == 'y':
break
else:
break
else:
key_entrada = input('That input does not exist in the dictionary, try again, Type only a valid key name:')
if entrada == 'n':
print('weno')
break
else:
entrada = input("Invalid Input, Type 'y' or 'n' without single quotation marks: ")
It should work as expected, however after testing it I got the following output:
All right, do you want to add a "None" item to an array in the dictionary? (y/n):y
Cool, now tell me at which key do you want me to add a "None" item? Type only a valid key name:Pinzas
you did not put single quotation marks, let me add them to your input
That input does not exist in the dictionary, try again, Type only a valid key name:'Pinzas'
Cool, now tell me at which key do you want me to add a "None" item? Type only a valid key name:'Pinzas'
That input does not exist in the dictionary, try again, Type only a valid key name:
I was pretty sure that I coded it right, but maybe I have omitted some important steps or done some "illegal" stuff here, so I would like to hear you guys what do you think it's making this program not working as expected?
The desired final output should be something like this:
the_dictionary_list:
{'Color': ['Amarillo.png', 'Blanco.png', 'Rojirosado.png', 'Turquesa.png', 'Verde_oscuro.png', 'Zapote.png'], 'Cuerpo': ['Cuerpo_cangrejo.png'], 'Fondo': ['Oceano.png'], 'Ojos': ['Antenas.png', 'Pico.png', 'Verticales.png'], 'Pinzas': ['None', 'Pinzitas.png', 'Pinzotas.png', 'Pinzota_pinzita.png'], 'Puas': ['None', 'Arena.png', 'Marron.png', 'Purpura.png', 'Verde.png']}
For a situation in which the user decided to update only the Pinzas
and Puas
keys.
CodePudding user response:
Problem solved, thanks to @JohnGordon, somehow he illuminated me:
entrada = input('All right, do you want to add a "None" item to an array in the dictionary? (y/n):')
while True:
if entrada == 'y':
key_entrada = input('Cool, now tell me at which key do you want me to add a "None" item? Type only a valid key name:')
while True:
if key_entrada in the_dictionary_list:
the_dictionary_list[key_entrada].insert(0, 'None')
key_entrada = input('Do you want to add another one? (y/n):')
if key_entrada == 'n':
entrada = 'n'
break
if key_entrada == 'y':
key_entrada = input('Cool, now tell me at which key do you want me to add a "None" item? Type only a valid key name:')
else:
key_entrada = input("Invalid Input, Type 'y' or 'n' without single quotation marks: ")
else:
key_entrada = input('That input does not exist in the dictionary, try again, Type only a valid key name:')
if entrada == 'n':
print('weno')
break
elif entrada != 'y' or entrada != 'n':
entrada = input("Invalid Input, Type 'y' or 'n' without single quotation marks: ")**strong text**