IndexError : list index out of range

66 views Asked by At
file=open("taxy.txt","r")
append=open("taxy.txt","a")
print("Do you want to hire or rent a car?")
choice=input("Click 1 to hire and 2 for renting")
if choice=="1":
    car_list = []
    price_list = []
    specification = []
    for lines in file:
        lines = lines.rstrip()
        temp_list = lines.split()
        car_list.append(temp_list[0])
        price_list.append(temp_list[1])
        temp_specification = ""
        for texts in range(2, len(temp_list)):
            temp_specification += " " + temp_list[texts]
        specification.append(temp_specification)
    car=input('Name of car you want to hire')
    if car not in car_list:
        print("This car is not available right now")

I have a txt file with specifications regarding cars, and their specifications. The error is in the line car_list.append(temp_list[0])

File "C:\Users\cramm\OneDrive\Desktop\Uni\Assignments\BN108\taxy.py", line 20, in car_list.append(temp_list[0]) Is the error message along with the IndexError: list index out of range

0

There are 0 answers