Python 这些代码行是做什么的?(运动模拟)

Python 这些代码行是做什么的?(运动模拟),python,object,methods,parameters,arguments,Python,Object,Methods,Parameters,Arguments,我们在我的计算机科学课上做一个活动,我很难理解几行代码的意思 以下是初始代码(用于您可能需要的任何背景信息) 我有一种大致的理解,但我的老师希望我们更具体一些。我也知道第二行是用参数1和2调用的,但我不确定这些数字在代码的其余部分中如何发挥作用。如果有人能帮我解释最后几行代码,我将不胜感激 设置初始变量: self.teamX = teamX # setting name self.scoreX = 0 # initial score self.teamAXco

我们在我的计算机科学课上做一个活动,我很难理解几行代码的意思

以下是初始代码(用于您可能需要的任何背景信息)


我有一种大致的理解,但我的老师希望我们更具体一些。我也知道第二行是用参数1和2调用的,但我不确定这些数字在代码的其余部分中如何发挥作用。如果有人能帮我解释最后几行代码,我将不胜感激

设置初始变量:

self.teamX = teamX        # setting name
self.scoreX = 0           # initial score
self.teamAXcorePoints = 1 # score increment
这两个是分数增量:

self.teamAScorePoints = 1
self.teamBScorePoints = 1
此处用于增加每个团队的得分:

def teamAScores(self):
    self.scoreA = self.scoreA + self.teamAScorePoints
def teamBScores(self):
    self.scoreB = self.scoreB + self.teamBScorePoints
现在是流程:

s = SportsMatch("Chargers", "Raiders") # defining the match
s.setScorePoints(1, 2)                 # setting initial score increments
s.teamAScores()                        # team A scores 1 point
s.teamBScores()                        # team B scores 2 points
s.teamAScores()                        # team A scores another 1 point
s.teamBScores()                        # team B scores another 2 points
s.whoWins()                            # prints winner

设置初始变量:

self.teamX = teamX        # setting name
self.scoreX = 0           # initial score
self.teamAXcorePoints = 1 # score increment
这两个是分数增量:

self.teamAScorePoints = 1
self.teamBScorePoints = 1
此处用于增加每个团队的得分:

def teamAScores(self):
    self.scoreA = self.scoreA + self.teamAScorePoints
def teamBScores(self):
    self.scoreB = self.scoreB + self.teamBScorePoints
现在是流程:

s = SportsMatch("Chargers", "Raiders") # defining the match
s.setScorePoints(1, 2)                 # setting initial score increments
s.teamAScores()                        # team A scores 1 point
s.teamBScores()                        # team B scores 2 points
s.teamAScores()                        # team A scores another 1 point
s.teamBScores()                        # team B scores another 2 points
s.whoWins()                            # prints winner

代码的一般说明:

s = SportsMatch("Chargers", "Raiders")
这行代码从
SportsMatch
类调用
\uuuu init\uuuu
方法,并传递方法“Chargers”和“Raiders”。然后将其保存为运动队的名称

s.setScorePoints(1, 2)
此行从类中调用
setScorePoints
方法,并将其传递给
1
2
。这些值保存为每个团队得分将在得分时增加的金额

s.teamAScores()
s.teamBScores()
s.teamAScores()
s.teamBScores()
这些行调用
teamAScores
teamBScores
方法。这些方法根据调用的方法增加团队的分数

s.whoWins()
这将调用类的
whoWins
方法,该方法比较团队得分并打印获胜团队


获胜的队伍将是B队,也称为突袭者。B组得分为
4
,a组得分为
2

代码的一般说明:

s = SportsMatch("Chargers", "Raiders")
这行代码从
SportsMatch
类调用
\uuuu init\uuuu
方法,并传递方法“Chargers”和“Raiders”。然后将其保存为运动队的名称

s.setScorePoints(1, 2)
此行从类中调用
setScorePoints
方法,并将其传递给
1
2
。这些值保存为每个团队得分将在得分时增加的金额

s.teamAScores()
s.teamBScores()
s.teamAScores()
s.teamBScores()
这些行调用
teamAScores
teamBScores
方法。这些方法根据调用的方法增加团队的分数

s.whoWins()
这将调用类的
whoWins
方法,该方法比较团队得分并打印获胜团队


获胜的队伍将是B队,也称为突袭者。B队得分为
4
,a队得分为
2

是运动刺激还是模拟这是运动刺激还是模拟p不
s.setScorePoints()
设置每次得分都会产生影响的增量吗?换句话说,它不会设置初始分数,它会设置每次球队得分时将添加的金额。Bob是对的,
setCorePoints
设置增量而不是初始分数。我的坏蛋。很抱歉更新答案非常感谢!它帮助了很多人看到它并排。谢谢你的帮助。(:不会
s.setScorePoints()
设置每次得分都会产生影响的增量?换句话说,它不会设置初始得分,而是设置每次球队得分时将添加的金额。Bob是对的,
setCorePoints
设置的是增量而不是初始得分。我的坏家伙。抱歉。更新的答案谢谢!帮助很大一起看。谢谢你的帮助。(: