Μπάμπης Μπουλής
Master of Science in Computer Engineering
Θέμα-Β Απαντήσεις (25 μονάδες)
Β1. (12 μονάδες)
Οθόνη
4 7 5
3 9
2 4
6 36
12 6 42
Β2. (13 μονάδες)
class soccerPlayer:
def __init__ (self,name,team, position,fouls,goals):
self.name=name
self.team=team
self.position=position
self.fouls=fouls
self.goals=goals
def scores(self,goal):
self.goals=self.goals+goal
def makesfoul(self,foul):
self.fouls=self.fouls+foul
player1=soccerPlayer(“messi”, “barcelona”, “forward”, 0, 45)
player2=soccerPlayer(“ramos”, “real”, “defence”, 10, 0)
player1.scores(2)
player2.makesfoul(3)
player1.makesfoul(1)
player2.scores(1)
player2.makesfoul(1)
player1.scores(1)
print “player1 fouls:”, player1.fouls,“goals:”,player1.goals
print “player2 fouls:”, player2.fouls,“goals:”,player2.goals
οθόνη |
>>> player1 fouls: 1 goals: 48 player2 fouls: 14 goals: 1 >>> |