Ticker

6/recent/ticker-posts

TCS IRA SBQ 31st Jan Python 2022

 HELLO DORAEMONS,

IN THIS BLOGPOST ,I HAVE SHARED THE RECENTLY ASKED PYTHON QUESTION AND SOLUTION WHICH IS CERTAINLY USEFUL WHEN YOU WANT TO PRACTICE.HOPE THIS BLOG IS USEFUL TO YOU.


Create a class Toy with below attributes


name of toy of type String 


brand of toy of type String

  

category of toy of type String 

quantity of available


toys of type int 


price of type int


Define the init_method to initialize the attributes of the objects to be created.

Create another class Toy Store with following attributes a List of Toy Objects

1. Create a method inside the Toy Store class

This method takes one argument -

A string value depicting the category of toy as the argument.

This method will find the toys with the given category of toys and arrange them in alphabetical order of brand. 

If brand is same then arrange in decreasing order of price. It will return the sorted list of toys.

ALL

If no Toy for the given Toy category is present in the Toystore, then the method should return None

2. Create another method inside Toy Store class. This method will return a dictionary of all the toys in ascending order of quantity The dictionary will have the

 toy name as the key and quantity as the value

Note: All string comparisons should be case insensitive.

Instructions to write main section of the code:

a. You would require to write the main section completely, hence please follow the below instructions for the same.

b. You would require to write the main program which is inline to the "sample input description section" mentioned below and to read the data in the same sequence.

Test Results

c. Create the respective objects (Toy and Toy Store) with the given sequence of arguments to fulfill the init_method requirement 

defined in the respective classes referring to the below instructions .

1. Create a list of Toys.

 To create the list

1. First read the number of Toys you want to store in the list.. 

2. Read the values for the Toy, create the Toy object and add to the list. This point repeats for the number of Toy objects (consider the input taken in point #1 above) to be created.

• First, read the name of the toy. 

̢ۢ Then read the Toy's brand material, category, quantity and price.

̢ۢFinally read the values for Toy's category which is passed as argument to the first method mentioned above.

ii. Create Toystore object by passing the List of Toy objects created in abova point # ci as the argument

d. Call the first method mentioned above from the main section and display the list of toys returned by the method You may refer to the sample output 

for the display format.

If method returns None, then display the message Toy with matching condition is not available in the Toy Store.' (excluding the quotes)

e. Call the second method mentioned above from the main section.

 Display the result value as mentioned in the method description. You may refer to the sample output for the display format. ( toy's name and quantity 

are to be displayed).


You can use/refer the below given sample input and output to verify your solution using 'Test against Custom Input' option in Hackerrank.

Input Format for Custom Testing

ALL

a. The 1st input taken in the main section is the number of Toy objects to be added to the list of Toys

b. The next set of inputs are the values related to attributes of Toy objects to be added to the Toys List. The above point repeats for the number of Toys objects, read in pointa 

c. The next line of input refers the Toy's category required to be passed as argument to the first method.


You can consider below sample input and output to verify your implementation before submitting in Hackerrank.


Input1:

5

Tuto

Hawk

A

12 

300

Dora 

Rock

A

30

295 

Pandora 

Hawk 

C2

20

550 

Bibushka 

Hawk

A

10 

290 

Car 

Hawk 

C2

78

600

A


Output: 


Bibushka 

Hawk

A

10 

290 

Tuto 

Hawk

A

12

300 

Dora 

Rock

A

30 

295

Bibushka 10 

Tuto 12 

Pandora 20 

Dora 30 

Car 78


Input 2:

5

Tuto 

Hawk

A

12

300

Dora

Rock

30

295

Pandora

Hawk

C2

20

550

Bibushka

Hawk

A

10

290

Car

Hawk

C2

78

600

B1


Output 2:

Toy with matching condition is not available in the ToyStore.

Bibushka 10

Tuto 12

Pandora 20

Dora 30

Car 78



IF YOUR CONFUSED AND DON'T KNOW HOW TO SOLVE THIS QUESTIONS. REFER TO THE BELOW VIDEO.I HAVE GIVEN DETAILED STRUCTURE TO FOLLOW AND EASIEST WAY TO SOLVE THIS QUESTION.


SOLUTION VIDEO FOR THIS QUESTION:

TCS IRA SBQ 31JAN PYTHON





HOPE THIS IS HELPFUL TO YOU GUYS.IF YOU LIKE MY WORK ,CONSIDER SUBSCRIBING TO MY CHANNEL AND FOLLOW MY BLOGPOST FOR MORE UPDATES



Post a Comment

0 Comments