Posts

Showing posts from September, 2020

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...