Inquirer with true or false

114 Views Asked by At

Is it possible to get a true or false value from an inquirer? Like if the user takes yes as an answer it gives me a true if no it gives false and not include that question in computing for an answer.

import inquirer
breakfast = [
    inquirer.List('breakfast',
    message="Do you take breakfast?",
    choices=['Yes', 'No'],
    ),
]
answers = inquirer.prompt(breakfast)
1

There are 1 best solutions below

0
Amit Mohanty On BEST ANSWER

You can easily convert the user's input from "Yes" or "No" to a Boolean (True or False).

import inquirer

breakfast = [
    inquirer.List('breakfast',
    message="Do you take breakfast?",
    choices=['Yes', 'No'],
    ),
]

answers = inquirer.prompt(breakfast)

# Convert the user's answer to a boolean value
takes_breakfast = answers['breakfast'] == 'Yes'

if takes_breakfast:
    print("User takes breakfast (True)")
else:
    print("User doesn't take breakfast (False)")