Welcome to Always Code
Recently, TCS conducted OPA on Python on 12th June 2020. This time they tried to confuse students with the question by giving input Five variables and initializing only four variables in Constructor. They also asked the students to implement a dictionary in the program.
Don't be confused. Read the full article and know how to clear any Python OPA easily by learning basic Object-Oriented Programming.
The question given in the OPA is Parking Management
These images may not be clearly visible. I will clearly explain the question
Note: If the question is large, don't get panic. It is one of the techniques to confuse the student. There is nothing in the question. All the questions in the TCS are similar since the time they started conducting OPA.
In Parking Management,
Create a class ParkedVehicle and initialize the variables vehicleSeq, fourWheeler, parkedFor, valetParking, and take another variable parkedStatus and set to "Parked".
Create another class ParkingLot and you need to implement two methods in it where the first method is updateParkedStatus and the second method is getParkingCharges.
Method 1 : updateParkedStatus
In this method, lotNumber is taken input from the main function and we need to change the parkedStatus of that lotNumber to "Cleared". For this, we need to check every object of ParkedVehicle to match with our required lotNumber.
Method 2 : getParkingCharges
In this method, lotNumber is taken as input and we need to calculate the parking charges of the vehicle. They have given two cases where if the vehicle is four Wheeler the parking charge is 50.0 Rs/Hr. If it is not a four Wheeler the parking charge is 30 Rs/Hr.
If there is valetParking, we should add another Rs 10.0
Main Function :
We should write our own main function. Don't feel it is difficult. Actually, it is very easy if you write according to Input TestCase. I will Leave the test Case below.
4
1
Yes
2.5
Yes
87
2
No
3.5
No
123
3
Yes
1.5
No
56
4
Yes
2
Yes
104
87
Output:
87 Cleared
135.0
Code:
Easy Way to Understand the program.
First Create a class ParkedVehicle to initialize all parked Objects. Using Constructor __init__(self) initialize all variables. It a 1 min task to completely write a program.
Next jump into main Function.
Take n as input for the number of objects and initialize all variables.
Create an object for class ParkingLot
Call the methods using the object
pl=ParkingLot(d)
li=pl.uPS(rv)
li1=pl.gPC(rv)
Next, Implement the Class ParkingLot. Read the question carefully and implement according to the question and return the values.
If you have any doubt in solving the question or any TCS OPA related doubts. Feel free to comment, I can help you within 1 hour.
If you want to get notified about TCS OPA solutions and coding Subscribe to this Blog.
Have a nice day.
Recently, TCS conducted OPA on Python on 12th June 2020. This time they tried to confuse students with the question by giving input Five variables and initializing only four variables in Constructor. They also asked the students to implement a dictionary in the program.
Don't be confused. Read the full article and know how to clear any Python OPA easily by learning basic Object-Oriented Programming.
The question given in the OPA is Parking Management
These images may not be clearly visible. I will clearly explain the question
Note: If the question is large, don't get panic. It is one of the techniques to confuse the student. There is nothing in the question. All the questions in the TCS are similar since the time they started conducting OPA.
In Parking Management,
Create a class ParkedVehicle and initialize the variables vehicleSeq, fourWheeler, parkedFor, valetParking, and take another variable parkedStatus and set to "Parked".
Create another class ParkingLot and you need to implement two methods in it where the first method is updateParkedStatus and the second method is getParkingCharges.
Method 1 : updateParkedStatus
In this method, lotNumber is taken input from the main function and we need to change the parkedStatus of that lotNumber to "Cleared". For this, we need to check every object of ParkedVehicle to match with our required lotNumber.
Method 2 : getParkingCharges
In this method, lotNumber is taken as input and we need to calculate the parking charges of the vehicle. They have given two cases where if the vehicle is four Wheeler the parking charge is 50.0 Rs/Hr. If it is not a four Wheeler the parking charge is 30 Rs/Hr.
If there is valetParking, we should add another Rs 10.0
Main Function :
We should write our own main function. Don't feel it is difficult. Actually, it is very easy if you write according to Input TestCase. I will Leave the test Case below.
4
1
Yes
2.5
Yes
87
2
No
3.5
No
123
3
Yes
1.5
No
56
4
Yes
2
Yes
104
87
Output:
87 Cleared
135.0
Code:
#ParkedVehicle class# k=list(self.d.keys()) creates list for all keys in dictionary
class ParkedVehicle:
def __init__(self,vehicleSeq,fourWheeler,parkedFor,valetParking):
self.vehicleSeq=vehicleSeq
self.fourWheeler=fourWheeler
self.parkedFor=parkedFor
self.valetParking=valetParking
self.parkedStatus="Parked"
#Implement ParkingLot class and methods
class ParkingLot:
def __init__(self,d):
self.d=d
def uPS(self,rv):
l=[]
k=list(self.d.keys())
for i in range(len(k)):
if(k[i]==rv):
self.d[k[i]].parkedStatus="Cleared"
l.append(rv)
l.append(self.d[k[i]].parkedStatus)
return l
return None
def gPC(self,rv):
k=list(self.d.keys())
pc=0
for i in range(len(k)):
if(k[i]==rv and self.d[k[i]].fourWheeler=="Yes"):
pc=50.0*self.d[k[i]].parkedFor
if(self.d[k[i]].valetParking=="Yes"):
pc=pc+10
elif(k[i]==rv and self.d[k[i]].fourWheeler=="No"):
pc=30.0*self.d[k[i]].parkedFor
if(self.d[k[i]].valetParking=="Yes"):
pc=pc+10
return pc
#Implement main function - Refer the instructions mentioned in the Qn text related to main function.
n=int(input())
pv=[]
d={}
for i in range(n):
vehicleSeq=int(input())
fourWheeler=input()
parkedFor=float(input())
valetParking=input()
lnum=int(input())
p=ParkedVehicle(vehicleSeq,fourWheeler,parkedFor,valetParking)
d.update({lnum:p})
pv.append(p)
rv=int(input())
pl=ParkingLot(d)
li=pl.uPS(rv)
if(li==None):
print("Lot Number Invalid")
else:
print(*li)
li1=pl.gPC(rv)
if(li1==0):
print("Lot Number Invalid")
else:
print(li1)
Easy Way to Understand the program.
First Create a class ParkedVehicle to initialize all parked Objects. Using Constructor __init__(self) initialize all variables. It a 1 min task to completely write a program.
Next jump into main Function.
Take n as input for the number of objects and initialize all variables.
Create an object for class ParkingLot
Call the methods using the object
pl=ParkingLot(d)
li=pl.uPS(rv)
li1=pl.gPC(rv)
Next, Implement the Class ParkingLot. Read the question carefully and implement according to the question and return the values.
If you have any doubt in solving the question or any TCS OPA related doubts. Feel free to comment, I can help you within 1 hour.
If you want to get notified about TCS OPA solutions and coding Subscribe to this Blog.
Have a nice day.
Post a Comment