Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyBatScoreAbs
#python 3.6.9 #PyBatScoreAbs #this code is created by Rezaul Hoque on April 12,2022; #contact: jewelmrh@yahoo.com; Dhaka, Bangladesh,https://rezaulhoque.wordpress.com;https:hoquestake.blogspot.com #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; from abc import ABC,abstractmethod class Person(ABC): def __init__(self,first, last): self.first = first self.last = last @property def filast(self): return f"{self.first} \t {self.last}" class Batter(Person): def __init__(self,first,last,match,run): super().__init__(first,last) self.run = run self.match=match def mscore(self): return self.run def matchno(self): return self.match def mavg(self): return self.run/self.match class Detail: def __init__(self): self.runlist= [ ] def add(self,score): self.runlist.append(score) #private method def __banner(self): print("Batters' score of a team:\n") print("~"*35) print("~"*35) print("name(first,last) match run avg\n") def totm(self): total=0 for s in self.runlist: total += s.matchno() return total def tot(self): total=0 for s in self.runlist: total += s.mscore() return total def display(self): for i in self.runlist: ##important:string objects are not callable like i.filast();they should be called like i.filast print(f"{i.filast}\t{i.matchno()}\t{i.mscore()}\t{i.mavg()}") if __name__ == '__main__': det = Detail() det._Detail__banner() det.add(Batter('hh','cc',5,182)) det.add(Batter('tt','nn',6,270)) det.add(Batter('yy','mm',8,350)) det.display() print("-"*35) print("Total ",det.totm()," ",det.tot())
run
|
edit
|
history
|
help
0
Mixing string with number
replace
regu
Simple calculator
Game4
Email_Python
dict()
питон
python lesson 1 function
molecular mass