Jac Mulder
Jac Mulder

Reputation: 47

How do I make the random.choice print the same result in Python?

First off I want to say thank you for taking the time to help others.

I need help getting the random.choice to print the same result from the list. I am now working on a text adventure game where players can make and deliver pizzas to the customer.

Here is part of my code where the boss in the game ask me to make a pizza for a customer:

def making_pizza(self):
    while True:
        print("Joe:" + mPlayer.name + " we have a customer by the name of  " + self.name)
        time.sleep(a)
        print("Joe: He would like a " + str(self.pizza_want))
        time.sleep(a)
        print("The address is " + self.address)
        time.sleep(a)
        accept = input('Do you accept? (Yes/No):')
        if accept == 'Yes' or accept == 'yes':
            pizza_menu()
        elif accept == 'No' or accept == 'no':
            print("Joe: Fine I'll find someone else for the job.")

Heres the method call:

random.choice(customer_list).making_pizza()

Now after the player finish making the pizza he has to deliver the pizza to the correct address:

def delivering(self, a, b, c, d,):
        choice_input = input(f"""

                        1 - {a}
                        2 - {b}
                        3 - {c}
                        4 - {d}
                        5 - {self.address}

            **** Choose the customer house to deliver the pizza ****

But when I use random.choice(customer_list) as an argument to call the delivering method it shows another random self.address from the customer list. How do I get the random.choice to show the correct address from the first method? which is the making_pizza method.

Thanks!

Upvotes: 1

Views: 514

Answers (1)

surftijmen
surftijmen

Reputation: 904

You should 'store' your choice as a variable:

choice = random.choice(customer_list).making_pizza()
print(choice)

because otherwise it prints another random choice and now it stores it in a variable so you can re-use that variable to print it.

Upvotes: 2

Related Questions