python - 什么才算算法?

标签 python python-3.x algorithm class

class Athlete:
  def __init__(self, name, points):
    self.name = name
    self.points = points

  def calculateRacePoints(name):
    for i in range(eventTotalVar):
      racePoints = checkOverallPlacement(placementVar, eventType=eventVar) + checkPercentagePlacement(placementVar, totalVar, eventType=eventVar) + checkImprovement(seedTime, prelimTime, finalTime) # uses created 2 functions and finds the total
      racePoints = racePoints + racePoints

    return float(racePoints / eventTotalVar)

这基本上是用输入的规范创建一个运动员。它将返回比赛中获得的平均分数(总分数除以赛事数量)。

有资格作为算法吗?如果是这样,我其中的两个函数也符合算法的资格吗? 具体是什么构成了算法,呃,算法?

最佳答案

牛津词典将算法定义为:

"A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer".

根据该定义,像 print("Hello World") 这样简单的东西在技术上将被视为一种算法。

查看您的代码:

class Athlete:
  def __init__(self, name, points):
    self.name = name
    self.points = points

  def calculateRacePoints(name):
    for i in range(eventTotalVar):
      racePoints = checkOverallPlacement(placementVar, eventType=eventVar) + checkPercentagePlacement(placementVar, totalVar, eventType=eventVar) + checkImprovement(seedTime, prelimTime, finalTime) # uses created 2 functions and finds the total
      racePoints = racePoints + racePoints

    return float(racePoints / eventTotalVar)

您有多种算法在工作。

级别运动员

  • 包含两种或多种算法
  • 包含逻辑和数学概念

def __init__(self, 名字, 分数)

  • 解决了描述运动员是谁或是什么的问题
  • 它允许您创建一名运动员并为该运动员提供名称和得分

defcalculateRacePoints(名称)

  • 解决与运动员互动的问题
  • 它可以让您获取有关该运动员的得分的信息

您的两个类方法都是算法,它们协同工作以帮助程序创建新的运动员并与他们交互。

我想您需要提供更多详细信息才能完成作业,但我希望这能让您开始。

关于python - 什么才算算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61822629/

相关文章:

python - Tkinter 自定义窗口

python - 在 Fedora 上运行 python 脚本时没有名为 lxml.html 的模块

python - 队列和线程的并发请求

python - 如何在 python 中创建优化的 3D 体积打包函数?

performance - 在通过节点子集的 2 个节点之间的图中查找最短路径

python - 具有嵌套函数作用域的 UnboundLocalError

python - 从类初始化器内部调用方法是Pythonic吗?

使用 -m 开关运行时,Python3 子模块安装程序不会更新路径

arrays - 为什么这个算法稳定,我怎么能让它不稳定?

python - pytorch 中的 tf.cast 等价物?