Random gen code error

Question: Trying to create random gen story, except printing every section instead of three

Repl link: day4_100 days - Replit

code snippet 
#random choice function
  start = [o1(), o2(), o3()]
  middle = [m1(), m2(), m3()]
  end = [e1(), e2(), e3()]

  random.choice(start)
  random.choice(middle)
  random.choice(end)
start = [o1(), o2(), o3()]
middle = [m1(), m2(), m3()]
end = [e1(), e2(), e3()]

random.choice(start)
random.choice(middle)
random.choice(end)

You call the function when putting it in the list. But you shouldn’t. If you call it, it runs the function and gives the return value (even inside a list). If you don’t call it, then the value is the function object itself, which you want so that you can pick a random function.

start = [o1, o2, o3]
middle = [m1, m2, m3]
end = [e1, e2, e3]

At the end, you need to call the function.

random.choice(start)()
random.choice(middle)()
random.choice(end)()
3 Likes

Thank you so much, I’m grateful you could help explain that in detail too me as this is all too new to me!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.