Help with this problem

list1=[]
list2=[]

class Parking:
    def __init__(self,slno,type,time,vehno):
        self.slno=slno
        self.type=type
        self.time=time
        self.vehno=vehno
def add(obj):
    if obj.type in list1:
         if len(list1)<3:
             list1.append(obj)
             print(list1)

    else:
        if len(list2)<3:
            list2.append(obj)
            print(list2)

def remover(slotno,type):
    if type=='2':
        for obj in list1:
            if obj.slno==slno:
                list1.remove(obj)
                print(list1)
                break





b=True
while b:
    choice=input('Enter 1 to add 2 to remove 3 to view')
    if choice=='1':
        slno=int(input('Enter slotno'))
        type=int(input('Enter type'))
        time=int(input('Enter time'))
        vehno=input('Enter vehno')
        obj=Parking(type,slno,time,vehno)
        add(obj)
    elif choice=='2':
        slno=int(input('Enter slotno'))
        type=int(input('Enter type of vehicle'))
        remover(type,slno)
    elif choice=='3':
        print('Printing 2 Wheeler list')
        for obj in list1:
            print(obj.slotno)
            print(obj.vehno)
    else:
        b=False



Hi, I’m trying to create a class (Parking) with input but I’m not getting the result since I’m missing something. Pls help.
slno=slot no
vehno=vehicle no
type= for 2 wheelers
time=duration

Hey, what are you trying to achieve?

What is the use of these lists here and

Why can’t I append if len(list1)<3
Please explain, so that I can answer…


type is integer

You’re comparing with string

Thank you so much!!! This is much easier to understand :smiley:

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

This is about a parking list. So they only let 2wheelers and 4 wheelers(list1,list2).Each of them got only 3 slots and anything more than that means slot is full.
The parking list got type,slot no,vehicle no: and time as properties.
So I need to create a function to add when a vehicle comes for parking and a remove function when vehicle leaves.

yeh sorry was just bored and sleepy. wont happen again maybe

I suggest naming those lists as 2_wheelers and 4_wheelers or something like that…
In the add function just check if list is full and return a message if it’s full otherwise add the vehicle to list

if obj.type==2:
    if len(list1)==3: return "Parking slots full"
    else:
        #add obj to list1(add specific property(eg. number))
         return "obj added to list1, vehicle parked"
else:
    if len(list2)==3: return 'Car can't be parked'
    # add obj to list2(maybe add vehicle number only)
    return f'{obj.number} parked'

Refer remover below

if type==2:
    for obj in list1: 
         if obj.slno==slno:
               # remove the item
               return 'object removed'
else:
    # Implement above steps for list2

Let me know if there’s another error