0

How do I make it choose a different question each time?

import random

name = input("What is your name? ")

def main():

    def feeling():
        response = input("How are you feeling right now {name}?".format(name=name))
        if response == "tired":
            tired = ['I wish I can make you feel better.','I hope school is not making you feel stressed.','You deserve the right to relax.']
            print(random.choice(tired))
        else:
            exit()

    def homesick():
        response = input("Do you miss your home? ")
        if response == "yes":
            yes=["Don't worry, you will be home soon......",'I am protecting your family and loved ones, trust me on this.',"Your kingdoms has been waiting for a long time, they'd forgiven your mistakes"]
            print(random.choice(yes))
        else:
            exit()

    def miss():
         response = input("Who do you miss?")
         if response == "my mom":
             print("Mom will be in town soon")
         else:
             exit()

    prompts = [feeling, homesick, miss]
    random.choice(prompts)()

    main()

main()
cigien
  • 57,834
  • 11
  • 73
  • 112
  • Do you mean how do you ask all 3 questions, but in a random order? – Sayse Jan 11 '18 at 07:23
  • [shuffle](https://stackoverflow.com/q/976882/1324033) and then use a loop – Sayse Jan 11 '18 at 07:24
  • https://stackoverflow.com/a/976918/3592113 – Yonatan Kiron Jan 11 '18 at 07:26
  • Check out this post. It should help you: https://stackoverflow.com/questions/5465455/syntax-to-call-random-function-from-a-list – Daniel Long Jan 11 '18 at 07:31
  • 1
    Please don't vandalize your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](https://creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed, and thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work?](/help/what-to-do-instead-of-deleting-question) – cigien Mar 29 '21 at 04:39

1 Answers1

2

random.shuffle does the business, shuffling a list.

import random

name = input("What is your name? ")

def main():

    def feeling():
        response = input("How are you feeling right now {name}?".format(name=name))
        if response == "tired":
            tired = ['I wish I can make you feel better.','I hope school is not making you feel stressed.','You deserve the right to relax.']
            print(random.choice(tired))
        else:
            exit()

    def homesick():
        response = input("Do you miss your home? ")
        if response == "yes":
            yes=["Don't worry, you will be home soon......",'I am protecting your family and loved ones, trust me on this.',"Your kingdoms has been waiting for a long time, they'd forgiven your mistakes"]
            print(random.choice(yes))
        else:
            exit()

    def miss():
         response = input("Who do you miss?")
         if response == "my mom":
             print("Mom will be in town soon")
         else:
             exit()

    prompts = [feeling, homesick, miss]
    random.shuffle(prompts)
    for prompt in prompts:
        prompt()

    main()

main()

Explanation:

random.shuffle(prompts) takes a list (prompts) and shuffles it like a hand of cards, so they are in a random order.

We then use a for loop to look at every element in prompts: "for prompt in prompts:"

And for each prompt, run the prompt by using "prompt()"

JimmyCarlos
  • 1,934
  • 1
  • 10
  • 24