0

I created this function definition in python:

def random_person():
    mylist = ["wounded priestress", "crying girl"]
    return random.choice(mylist)

Now I want to call that function in a print function in my code:

print("In the temple, you find a random_person().")

Unfortunately, it does not result in the strings I have chosen for my random function. This is what I get:

In the temple, you find a random_person().
Christian K.
  • 2,785
  • 18
  • 40
Onizuka92
  • 99
  • 1
  • 7

2 Answers2

2

Just thought I'd compile all the options I listed in the comments :)

print(f"In the temple, you find a {random_person()}.") # my personal favorite
print("In the temple, you find a", random_person(), ".")
print("In the temple, you find a {}.".format(random_person()))
print("In the temple, you find a %s." % random_person())

And @Jean-Francois' too:

print("In the temple, you find a "+random_person()+".")
Have a nice day
  • 1,007
  • 5
  • 11
0

Give this a try.

import random
def random_person():
   mylist = ["wounded priestress", "crying girl"]
   return random.choice(mylist)
print(f"In the temple, you find a {random_person()}.")

It uses f-strings a way better way than +str()+

Buddy Bob
  • 5,829
  • 1
  • 13
  • 44