0

I'm basically trying to create something of an mad libs generator. When it runs through all the random variables, and I try to get it to save as a variable, and then print that variable I get "none"

I'm a novice so I apologize if this is painfully dumb. Link to colab notebook where you can see it: https://colab.research.google.com/drive/1Eh0-ACUJOduxjRbsql7ut_VgZEE4PBWW?usp=sharing

This is the code

import random

#Word Buckets
list = ("Todd", "Jill","Mary")
secondlist = ("hot","cold","run" )
thirdlist = ('pizza','pasta',"wine" )


#Create Define random choices
def def1 ():
  d=random.choice(list)
  a=random.choice(secondlist)
  r=random.choice(thirdlist)
  c=random.choice(list)
  print(d,a, (r+"'s"),c)

def def2 ():
  d=random.choice(list)
  a=random.choice(secondlist)
  f=random.choice(thirdlist)
  fv=random.choice(thirdlist)

  print(fv, "Because of",(d+"'s"),f)


titletype = (def1, def2)
#random.choice(titletype)()
message=random.choice(titletype)()
print(message)

And that will return None

  • 2
    The two functions are lacking a `return` statement. Additionally, I’d recommend changing the `list` variable name to something else, as it’s currently overwriting the builtin type. – S3DEV Nov 26 '20 at 18:55
  • nitpick on wording: technically, `(...)` are not _lists_, they are _tuples_. Use `[...]` for lists. – Pac0 Nov 26 '20 at 18:57

1 Answers1

0

def2 and def1 should return instead of print

Gerard Bro
  • 107
  • 3
  • 2
    This is correct, but you might want to show the OP what you mean. They note they are a novice so your answer isn't that clear. – gph Nov 26 '20 at 19:08
  • Ah! I thought the print might be the error. But return makes sense. Only issue is now i'm getting a return ('Todd', 'run', "wine's", 'Mary'), which I think I can convert into a string. No big deal. I think I can just create a little function. – user10583271 Nov 26 '20 at 19:40
  • @user10583271 - Pease remember to click the tick next to the answer which helped you, to show it as accepted. This is a standard SO practice. – S3DEV Nov 27 '20 at 12:18