Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Beginner Input and different choise

Tags:

python

Though there is probably an easier way to do it, but I wish to understand what is wrong.The code should tell you the real identity of a superhero when given the superhero's name.

Here is the problem:

After you provide the superhero's real name, it would ask "Do you need more information?"; How do you setup a choice for this question?

super_heros = {'Hulk': 'Bruce Banner',
               'Capitan America': 'Steve Rogers',
               'Spiderman': 'Peter Parker'}
hero_biography = {'Bruce Banner' : 'David Banner nasce in California...ecc'}

while True:
    choice = input('Nome Supereroe:') ###Superhero's name:
    if choice == 'Hulk':
        print(super_heros['Hulk'])
    elif choice == 'Bruce Banner':
        choice = input('Desideri maggiori informazioni?') ###Do you want more information
    elif choice == 'Yes': ### I know that this one will refer to : choice = input('Nome Supereroe:')
        print(hero_biography['Bruce Banner'])
    elif choice == 'Capitan America':
        print(super_heros['Capitan America'])
    elif choice == 'Spiderman':
        print(super_heros['Spiderman'])
    elif choice == 'Esc':
        break
    else:
        choice == ''
        print('Nome inesistente')
like image 747
Federico Di Lembo Avatar asked Apr 01 '26 10:04

Federico Di Lembo


1 Answers

Use a nested condition with another variable, e.g. choice2

...
elif choice == 'Bruce Banner':
    choice2 = input('Desideri maggiori informazioni?')
    if choice2 == "Yes":
        print(hero_biography['Bruce Banner'])
elif choice == 'Captain America':
...
like image 197
Iskren Avatar answered Apr 02 '26 23:04

Iskren