dimanche 5 mai 2019

if\else statement: read a text file, and append it to a list at a specific index

The def workout: reads the workout.txt file, then adds the specific workout to a list(self.roster), based on the session number. when i run the program, it doesn't print the workout of the client, based on the session number

def workout(self):
          if self.session == '1':
            file = open('workout.txt','r')

            for x in file:
               list = []
               item = x.strip().split(",")
               list.append(item)
               z = (item[:7])
               self.workout.append(z)
               #self.workout.append()
               self.roster.append(z)
               return list[:7]

          elif self.session == '2':
            file = open('workout.txt','r')

            for x in file:
               list = []
               item = x.strip().split(",")
               list.append(item)
               z = (item[:14])
               self.workout.append(z)
               #self.workout.append()
               self.roster.append(z)
               return list[:14]

          elif self.session == '3':
            file = open('workout.txt','r')

            for x in file:
               list = []
               item = x.strip().split(",")
               list.append(item)
               z = (item[:25])
               self.workout.append(z)
               self.roster.append(z)
               #self.workout.append()
               return list[:25]

          elif self.session == '4':
            file = open('workout.txt','r')

            for x in file:
               list = []
               item = x.strip().split(",")
               list.append(item)
               z = (item[:33])
               self.workout.append(z)
               self.roster.append(z)
               #self.workout.append()
               return list[:33]

def printRoster(self):
       for z  in self.roster:
           print('\n ')
           print(z)      

Trainer and Client

Trainer:Anthony Grant Age:23 Gender:Male

Name:Alex Age:24 Gender:Male Weight:180.0 Height:1.79 BMI:main.Client object at 0x03C1F3B0>> Status:main.Client object at 0x03C1F3B0>> Plan:shred Session: 1 CLIENT WORKOUTS[] #Here should have the clients specific workout, based on their session number

Aucun commentaire:

Enregistrer un commentaire