Page 412 - Computer Science V2.0 Class 11
P. 412

Approach:
                    a.  First create a tuple of categories:
                      clothCategory = ('wedding', 'casual', 'party', 'sports')
                    b.  Intialise count of each type of clothing to 0:
                      countW,countC, countP, countS  = 0, 0, 0, 0
                    c.  For each input (type of clothing):
                      i.  If in the clothCategory, increment the appropriate count
                      ii.  Otherwise print an error message
               Ans.  '''
                    Objective: To count clothing for each category
                    Input: clothing ids, clothing names, and clothing categories
                    Output: category-wise count
                    '''
                    clothCategory = ('wedding collection', 'casual wear', 'party wear', 'sports wear')
                    countW, countC, countP, countS = 0, 0, 0, 0
                    continueOrNot = 'y'
                    clothingList = []


                    while continueOrNot =='y':
                        clothingId = int(input("Enter the clothing id :  "))
                        clothingName = input("Enter name of the clothing :  ")
                        inputCategory = input("Enter category of clothing :  ")

                        if inputCategory not in clothCategory:
                            print(" Sorry...We do not deal with ", inputCategory)
                            continue

                        clothRecord = [clothingId,clothingName,inputCategory]

                        clothingList.append(clothRecord)
                        continueOrNot = input(" Do you wish to continue (y/n):  ")
                    for record in clothingList:
                        if record[2] == 'wedding collection':
                            countW += 1
                        elif record[2] == 'casual wear':
                            countC += 1
                        elif record[2] == 'party wear':
                            countP += 1
                        elif record[2] == 'sports wear':
                            countS += 1
                    print(clothingList)
                    print("Category Wise data is :   ")
                    print('Wedding Collection: ', countW)
                    print('Casual Wear: ', countC)
                    print('Party Wear: ', countP)
                    print('Sports Wear: ',countS)

               398   Touchpad Computer Science (Ver. 2.0)-XI
   407   408   409   410   411   412   413   414   415   416   417