Why is my variable not being incremented properly

I was working on a project for fun and the main function of the project is to take some information from one file and see if any of the vehicles match a plate on a different file and if they do then the program records the amount of expired vehicles based on their type. At the end the program launches a bar graph with the info.

This is the first file with vehicles on the highway (type – plate # – speed):
car – ABCD123 – 90
truck – XYZW456 – 100
bus – PQRS789 – 95
car – MNOP234 – 105
truck – UVWX567 – 88
bus – EFGH890 – 102

This is the plates that are in the expired file:
ABCD123

This is my code:
import matplotlib.pyplot as plt

def main():
“””
This function aims to read the file which has the list of highway vehicles
and take action
“””

expired_cars = 0
expired_trucks = 0
expired_buses = 0
speeds = []
plates = []
vehicles = []

with open('HighwayData.csv', 'r') as f:
    lines = f.readlines()

    for line in lines:
        info = line.strip().split('-')
        print("Info:", info)  # Debugging statement
        vehicle_type = info[0]
        plate = info[1]
        speed = info[2]

        """if check_expiry(plate) is True:
            if vehicle_type == 'truck':
                expired_trucks += 1
            elif vehicle_type == 'car':
                expired_cars += 1
                print("Expired Cars Count:", expired_cars)  # Debugging statement
            elif vehicle_type == 'bus':
                expired_buses += 1"""

        speeds.append(int(speed))
        plates.append(str(plate))
        vehicles.append(str(vehicle_type))

for i in range(len(plates)):
    if check_expiry(plates[i]):
        print(vehicles[i])
        if vehicles[i] == "truck":
            expired_trucks += 1
        elif vehicles[i] == "car":
            expired_cars += 1
        elif vehicles[i] == "bus":
            expired_buses += 1


average = find_average_speed(speeds)

print("Expired Cars:", expired_cars)  # Debugging statement
print("Expired Trucks:", expired_trucks)  # Debugging statement
print("Expired Buses:", expired_buses)  # Debugging statement
print("Average Speed:", average)  # Debugging statement


make_graph([expired_trucks, expired_cars, expired_buses, average])

def check_expiry(plate: str) -> bool:
“””
This function aims to check if the vehicle has a expired plate or not
“””
with open(‘ExpiredPlate.csv’, ‘r’) as s:
lines = s.readlines()

    for line in lines:
        info = line.strip()
        print("Plate in file:", info)  # Debugging statement


        if plate.strip() == info:
            print("Plate matched:", plate)  # Debugging statement
            return True
        else:
            print("Plate not matched:", plate)  # Debugging statement


return False

def find_average_speed(speeds_list: list[int]) -> int:
“””
This function aims to calculate the average speed
“””
total = 0
for i in speeds_list:
total += i

average_speed = total // len(speeds_list)

return average_speed

def make_graph(data):
‘(x: list[str], y: list[int])’
“””
This function aims to launch the graph of the data which is read from the file
“””

x_values = ['truck', 'car', 'bus', 'average speed']
#y_values = [expired_trucks, expired_cars, expired_buses, average]

plt.bar(x_values, data)

plt.xlabel('Vehicle Types')
plt.ylabel('Expired Vehicles')
plt.title('Number of Expired Vehicles On Highway')

plt.show()

if name == “main“:
main()

I have tried many different approaches such as putting into a list and the one I have commented but every time the expired is 0 and when outputted the programs says no expired trucks (that’s right), no expired cars (that’s wrong it should be 1), no expired buses (that’s right), and the speed is calculated and graphed properly.

I have tried to match the plates by putting them into a list and trying them separately and what I find is that the program matches the plates correctly but doesn’t update. Also there are some debugging statements in the code.

New contributor

Gaming Titan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật