【问题标题】:Include the result of a function in a Python string在 Python 字符串中包含函数的结果
【发布时间】:2018-01-18 02:35:05
【问题描述】:

尝试通过一些初学者 Python 代码来工作。

我需要提供一个字符串,给出 3 个数字 a、b 和 c,状态为 The average is: XX

如何将sum(a,b,c) / len(a,b,c) 合并到输出字符串中?

【问题讨论】:

  • documentation 是你的朋友。
  • 将问题减少到最少的信息量

标签: python string python-3.x average


【解决方案1】:
scores = [5, 4, 3, 4, 5]
avg = sum(scores)/len(scores)

print("Your average score: " + str(avg))

你是这个意思吗?

【讨论】:

  • 是的,这正是我想做的,但我不是从数字开始,而是从一个看起来像这样的字符串开始:def report_exam_avg(a, b, c): assert is_number(a) and is_number(b) and is_number(c)
猜你喜欢
  • 1970-01-01
  • 2021-05-30
  • 1970-01-01
  • 1970-01-01
  • 2015-10-17
  • 2012-02-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多