Random Number Selection with PyInquirer

  • Share this:

Code introduction


This function uses the PyInquirer library to create a multiple-choice question where the user selects a number between 1 and 10. The function then returns a randomly selected number from the user's choice.


Technology Stack : PyInquirer

Code Type : Python Function

Code Difficulty : Intermediate


                
                    
def select_random_number():
    from pyinquirer import ChoiceQuestion, prompt
    import random
    
    questions = [
        ChoiceQuestion('Select a number',
                       ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'])
    ]
    
    answers = prompt(questions)
    return random.choice(answers['Select a number'])                
              
Tags: