How to take total count of words in the list python 1

How to take total count of words in the list python

#How to find total count of "BMW" cars from the list

car_list = ["BMW", "Audi", "BMW", "Mercedez", "BMW", "Ferrari"]

count = 0

for cars in car_list:
    if cars == "BMW":
        count = count + 1
print("Total BMW Cars in Garage are:-", count)

Here is what the above code is Doing:
1. We have a list of cars in a garage.
2. We have a variable called count which is initialized to 0.
3. We have a for loop which iterates through the list of cars.
4. We have an if condition which checks if the car is BMW.
5. If the car is BMW, we increment the count by 1.
6. We print the total count of BMW cars in the garage.

Similar Posts