Python随机变量打印回“无”

2024-05-19 10:23:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我基本上是想创造一个疯狂的libs生成器。当它运行在所有随机变量中,我试图将其保存为变量,然后打印该变量时,我得到“无”

我是一个新手,所以我道歉,如果这是痛苦的愚蠢。链接到您可以看到的colab笔记本:https://colab.research.google.com/drive/1Eh0-ACUJOduxjRbsql7ut_VgZEE4PBWW?usp=sharing

这是密码

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)

这会回来的


Tags: messagedefrandomlibslistprintcolabchoice

热门问题