首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >转让(聊天机器人)

转让(聊天机器人)
EN

Stack Overflow用户
提问于 2017-01-16 11:41:54
回答 1查看 55关注 0票数 0

我的任务是:

创建一个菜单选项,让机器人打印今天的日期和时间、随机情绪、整数和浮点数。所有的东西都应该放在一个字符串句子里。

到目前为止,这就是我认为应该使用的东西。问题是我不知道该怎么把这一切组合起来。

代码语言:javascript
复制
def dateandfeels():
    """
    docstring
    """
    today = (time.strftime("%H:%M:%S"))
    time1 = (time.strftime("%d/%m/%Y"))
    whole = int(15)
    float1 = float(0.056)
    mood = ['happy', 'sad', 'moody', 'pythonic']
    moody = (random.choice(mood))

    print("""Today is {today}. Time is {time1}. My number of choice is {whole}
    and my float of choice is {float1}. Also I'm feeling a bit {moody} today""")

如果有人能提供一些帮助或建议如何使这件事进行,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2017-01-16 12:08:31

如果我明白你的意思,你需要这样的东西,对吧?

代码语言:javascript
复制
import time
import random
def dateandfeels():
  """
  docstring
  """
  toPrint="";
  today = (time.strftime("%H:%M:%S"))
  toPrint+=today;
  time1 = (time.strftime("%d/%m/%Y"))
  toPrint+=" "+time1;
  whole = int(15)
  toPrint+= " "+str(whole)
  float1 = float(0.056)
  toPrint+=" "+str(float1);
  mood = ['happy', 'sad', 'moody', 'pythonic']
  toPrint+=" "+''.join(mood);
  moody = str((random.choice(mood)))
  toPrint+=" "+moody;
  print("Here print the string: \n")
  print (toPrint+"\n")
  print("Here use printf like to print all variables: \n")
  print ("Today is %s. Time is %s. My number of choice is %d and my float of choice is %f. Also I'm feeling a bit %s today" %(today,time1,whole,float1,moody))

dateandfeels()

首先,我将所有变量添加到字符串中,然后打印它,而另一种方法是打印任何具有其类型的变量,对吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41675620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档