• Как обратиться к ключам словаря через input?

    SoreMix
    @SoreMix Куратор тега Python
    yellow
    Можно сделать словарь dynos, в котором будут два ключа: carno и maia. Ну и потом просто получать их.

    dinos = {'carno': { 'weight': 2170, 'health': 2170, 'bite': 200, 'bleed': 15, 'sbite': 0, 'sbleed': 0 }, 'maia': { 'weight': 2868, 'health': 2868, 'bite': 175, 'bleed': 0, 'sbite': 0, 'sbleed': 0 }}
    
    d1=dinos[input()]
    Ответ написан
    Комментировать
  • Как обратиться к ключам словаря через input?

    Vindicar
    @Vindicar
    RTFM!
    Засунь словарь в словарь.
    dinos = {
        'carno' : { 'weight': 2170, 'health': 2170, 'bite': 200, 'bleed': 15, 'sbite': 0, 'sbleed': 0 }
        'maia' : { 'weight': 2868, 'health': 2868, 'bite': 175, 'bleed': 0, 'sbite': 0, 'sbleed': 0 }
    }
    
    while True:
        print('Enter attacking dino name: ', end='')
        name = input()
        if name not in dinos:
            print(f'No such dino: {name}')
        else:
            dino = dinos[name]
            break
    #работаем с dino
    Ответ написан
    Комментировать