Part of the series

Several example codes

~2 min read • Updated Sep 17, 2025

Program Overview

This Python program simulates a traffic violation system.
There are 10 types of violations, each assigned a code from 0 to 9.
Each code has a specific fine amount.
For each vehicle, the program reads:
- License plate number
- Number of violations
- Violation codes
It calculates the total fine and displays it.
Entering -999 as the license plate number will terminate the program.


Python Code:


# Define fine amounts for violation codes 0 to 9
penalties = [100000, 200000, 150000, 300000, 250000, 180000, 220000, 270000, 160000, 190000]

while True:
    car_number = input("Enter vehicle license plate (enter -999 to exit): ")
    if car_number == "-999":
        print("Exiting program.")
        break

    count = int(input("Enter number of violations for this vehicle: "))
    total_fine = 0

    for i in range(count):
        code = int(input(f"Enter violation code #{i+1} (0 to 9): "))
        if 0 <= code <= 9:
            total_fine += penalties[code]
        else:
            print("Invalid violation code. Ignored.")

    print(f"Total fine for vehicle {car_number}: {total_fine} Rials\n")

Sample Output:


Enter vehicle license plate (enter -999 to exit): 45D123  
Enter number of violations for this vehicle: 3  
Enter violation code #1 (0 to 9): 2  
Enter violation code #2 (0 to 9): 5  
Enter violation code #3 (0 to 9): 7  
Total fine for vehicle 45D123: 600000 Rials

Enter vehicle license plate (enter -999 to exit): -999  
Exiting program.

Explanation:

Here’s how the program works:
- A list penalties stores fine amounts for each violation code
- The program reads vehicle data and violation codes
- It calculates the total fine by summing the corresponding penalty values
- If the user enters -999, the program exits


Written & researched by Dr. Shahin Siami