简体   繁体   English

什么是算法?

[英]What qualifies as an algorithm?

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)

This is basically creating an athlete with inputted specifications.这基本上是创建具有输入规格的athlete It will return the average points attained in the race (total points divided by number of events).它将返回比赛中获得的平均分(总分除以事件数)。

Do classes qualify as an algorithm? classes有资格作为算法吗? If so, do my two functions within it also qualify as an algorithm?如果是这样,我在其中的两个函数是否也有资格作为算法? What specifically makes an algorithm, well, an algorithm?什么让一个算法,好吧,一个算法?

Oxford Dictionary defines an Algorithm as:牛津词典将算法定义为:

"A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer". “在计算或其他解决问题的操作中要遵循的过程或一组规则,尤其是计算机”。

By that definition something as simple as print("Hello World") would technically be considered an algorithm.根据该定义,像print("Hello World")这样简单的东西在技术上将被视为一种算法。

looking at your code:查看您的代码:

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)

You have multiple algorithms at work.你有多种算法在工作。

class Athlete class 运动员

  • Contains two or more algorithms包含两个或多个算法
  • Contains logical and mathematical concepts包含逻辑和数学概念

def __init__(self, name, points) def __init__(self, name, points)

  • Solves the problem of describing who or what the athlete is解决了描述运动员是谁或什么的问题
  • It allows you to create an athlete and give that athlete a name and score/points它允许您创建运动员并为该运动员命名和得分/分数

def calculateRacePoints(name) def calculateRacePoints(名称)

  • Solves the problem of interacting with the athlete解决与运动员互动的问题
  • It allows you to get information about this athlete's score/points它允许您获取有关该运动员的得分/分数的信息

Both of your class methods are algorithms that work together to help the program create new athletes and interact with them.您的两种 class 方法都是协同工作以帮助程序创建新运动员并与他们互动的算法。

I would imagine you need to provide more detail to complete the assignment, but I hope this gets you started.我想你需要提供更多细节来完成作业,但我希望这能让你开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM