Code Problem: Take userinput from a file and execute the class and its function line by line. The userinput will be like a list with 10 or more values. I have reduced the number of items for discussion purpose. I can make the code work and get the output but wondering if there is any cleaner method which can be scaled easily.
Note: Python2.7 cannot use 3.7 yet
##Below is an example code and its output\\
class student():
def __init__(self,name,age,club):
self.name=name
self.age=age
self.club=club
def get_club(self):
if int(self.age)<10 and self.club=="lego":
print("Student :"+self.name+' is in: '+self.club+ ' club')
elif int(self.age)>15 and self.club=="football":
print("Student :"+self.name+' is in: '+self.club+ ' club')
else:
print("Student :"+self.name+' is in: '+self.club+ ' club')
ui=[("Jim,8,lego"),("Dwight,16,football"),("Pam,21,arts")]
for i in ui:
xy=i.split(',')
c=student(xy[0],xy[1],xy[2])
c.get_club()
\\
Code Output
Student :Jim is in: lego club Student :Dwight is in: football club Student :Pam is in: arts club