Posts

Python MCQ

print('abcd'.translate('a'.maketrans('abc', 'bcd'))) print('xyyzxxyxyy'.lstrip('xyy')) class Pet:     _class_info = "pet animals"     def about(self):         print("This class is about " + self._class_info + "!")    class Dog(Pet):     _class_info = "man's best friends" class Cat(Pet):     _class_info = "all kinds of cats" p = Pet() p.about() d = Dog() d.about() c = Cat() c.about() class Demo:      def __init__(self):          self.a = 1          self.__b = 1      def get(self):          return self.__b obj = Demo() obj.a=45 print(obj.a) class Class:         def __init__(self,num):                 self.__num=num                 self.value=0         def display_total(self):       ...

Python - 2 Questions | 40 minutes

Image
  INSTRUCTION :  Don't look at the answer until you have tried your best to solve the problem. The solution provided here is in case you are stuck in a situation, and you are extremely helpless to solve it out. Hope you will crack the logic. So let's start solving the problem. TOLLPLAZA TollPlaza A toll booth on the way to Bangalore wants to keep the track of the number of vehicles passed through it and total amount collected by them. Write a python program to implement the class diagram given below. Class description: Constructor:  Initialize both the instance variables, no_of_vehicle, total_amount to 0 count_vehicle():  Increment total number of vehicle by 1 calculate_amount(vehicle_type):  Accept vehicle type and identify toll amount for that vehicle based on details given in the table. Add it to the total_amount instance variable. collect_toll(owner_type,vehicle_type):  Accept owner type and vehicle type of the vehicle for which toll should be collected...

Basic Operations on Data using Pandas - Python

  EVENT MANAGEMENT - VII Event Management - VII   Sunil the event manager found that using some functionalities of Data science, it was possible to generate the descriptive statistics, the transpose of the data set also to sort the data set according to a particular column or value.   He provides his requirement to the development team. Now you being the part of the team, this requirement is assigned to you.   Write a code to describe, transpose and sort the data set.   Input Format: The input consists of a CSV file containing the data set of 10 rows and 10 columns followed by the choice (1/2/3/4) entered by the user.   The choice 1 corresponds to describe the  'NoOfDates','Expected Audience','HallPricePerDay','TotalCost' columns   in the dataset. The choice 2 corresponds to transpose the data set. The choice 3 corresponds to sort the data set by axis( 0  or  1 ). The choice 4 corresponds to sort the data set by value.   Output...

Dropping Columns and Changing the index of a dataframe - Python

  Event Management System II- Eliminate Column   Sunil, an event manager found his data set was cleaned by the development team and was as required. He also found that his data set was cleaned based on the missing values in rows. He thought it would be helpful if the data set was cleaned based on columns. So, he requests the development team to do the needful. Assume that you are currently working under development team. Frame a dataset (having 10 rows and 10columns of data) for Event Management System. Consider the threshold as all values should be available, (ie. all the values should be available in a column.) If any value is missing, then drop the particular column. Input Format: Create a CSV file containing the data set of 10 rows and 10 columns. NOTE: CSV File contains the comma seperated values as shown below. [SlNo,EventName,EventManager,NoOfDates,StartDate,EndDate,HallName,HallAddress,HallPricePerDay,TotalCost] Output Format:  The output should display the d...

Basic Operations on Data using NumPy

  FLATTENING TO THE DATAFRAME Flattening of the Dataframe   Ankit is going to  manage the event data . He is having the data as dataframe, and his manager wants to print those customers name who booked the event in the same month.  But the manager wants to print in the array format. So help Ankit to print customers name whose event month is same. And flatten the data and print in the array (list) format. The following is the 2D format for the dataframe:     customer_name, address, date, eventType, cost, noOfPeople Here eventType is described as marriage, get together, and mehndi.    Filled the data in the dataframe as the CSV file, in the above format. Input Format: For a sample dataframe, see the attached  CSV  file. Output Format: The output is the list of customers name with the month number of event booking. Sample Input: See the attached CSV file. Sample Output:   Flatten Data: ['Vikram' '02' 'Amit' '02'] Description of th...

Pyhton - ONE TO ONE RELATIONSHIP

  P11 / ONE TO ONE RELATIONSHIP – 2 P11 / One to One Relationship – 2   Create a class named  Address  with the following private_attributes __street __city __state   Include a constructor __init__(self, street, city, state)   Include a method __str__(self) This method returns a string corresponding to Address details in the format specified in the sample output.   Include @property decorator for state   Create a class named  Person  with the following private_attributes __name __age __address (of type Address)   Include a constructor __init__(self, name, age, address)   Include a method __str__(self) This method returns a string corresponding to Person details in the format specified in the sample output.   Include @property decorator for name   Include @property decorator for address   Create objects of the above classes and test them.   Input and Output Format: Refer Sample Input and Output for formatting...