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/