The following code will generate a number plate and then generate a random speed and see if it's speeding
import random, string, time
class Car:
def __init__(self):
self.plate = self.genPlate()
self.limit = 60
self.checkSpeeding()
def checkSpeeding(self):
self.speeding = random.randint(0, 1)
if self.speeding:
self.speed = random.randint(self.limit+3, self.limit+20)
else:
self.speed = random.randint(self.limit-20, self.limit+2)
def genPlate(self):
plateFormat = ['L', 'L', 'N', 'N', 'L', 'L', 'L']
genPlate = []
for i in plateFormat:
if i == 'L':
genPlate.append(random.choice(string.ascii_letters[26:]))
elif i == 'N':
genPlate.append(str(random.randint(0, 9)))
genPlate.insert(4, " ")
return "".join(genPlate)
allCars = []
x = 0
while True:
allCars.append(Car())
print(allCars[x].plate + " was going " + str(allCars[x].speed) + "mph in a " + str(allCars[x].limit) + "mph zone")
if allCars[x].speeding:
print("speeding fine issued")
print("\n")
time.sleep(5)
x += 1
Here is a link to the original source