Python parking management system can realize vehicle storage, query vehicles according to license plate number or model, modify vehicle information, realize billing when vehicles leave the library, according to the model Statistics The number of vehicles and the function of displaying all vehicle information
(1) Define the vehicle category. The attributes include license plate number, color, model (car, small, medium, and large), arrival time and departure time and other information and related behaviors of operating on attributes.
(2) Define a management category to complete the management of the parking lot. The specific requirements of the parking lot: the parking lot is a long and narrow passage that can park n cars, and there is only one gate for cars to enter and exit.
Cars wait in the parking lot on the sidewalk outside the door. Once there is a car driving away, the first car on the sidewalk can drive in; every car parked in the parking lot must press it when it leaves the parking lot The length of stay will be paid.
Function description
(1) Add function: [Program] (https://www.zalou.cn/tag/chengxu) can add the information of vehicles arriving at the parking lot, requiring the vehicle's license plate number to be unique. If a record with a duplicate number is added, it will prompt the data to be repeated and cancel the addition.
(2) Query function: query the vehicle information in the added parking lot according to the license plate number, car model, etc., if not found, the corresponding prompt information will be given, if found, the corresponding record information will be displayed;
(3) Display function: It can display the information of all vehicles in the current system, and each record occupies one line.
(4) Editing function: the corresponding records can be modified according to the query results, and the uniqueness of the license plate number should be paid attention to when modifying.
(5) Delete function: It mainly realizes the deletion of added vehicle records. If there is no corresponding personnel record in the current system, it will prompt "Record is empty!" and return to the operation.
(6) [Statistics] (https://www.zalou.cn/tag/tongji) function: [Statistics] (https://www.zalou.cn/tag/tongji) the total number of vehicles in the parking lot, according to the vehicle type, according to the arrival time [Statistics] (https://www.zalou.cn/tag/tongji) and so on.
First create a car-related class module setting_Car.py
import time
from setting_Manage import ParkManage
classCar(ParkManage):"""A class about cars"""
def __init__(self,car_number,car_owner,contact_way,car_color,car_model):super(Car, self).__init__()
self.car_number=car_number
self.car_owner=car_owner
self.contact_way=contact_way
self.car_color=car_color
self.car_model=car_model
self.balance=200
self.entrance_time =0
self.exit_time =0
def __setitem__(self, key, value):
self.__dict__[key]=value
def slot_card(self):"""Time-based billing"""
park_time=time.mktime(time.strptime(self.exit_time))- time.mktime(
time.strptime(self.entrance_time))
h=park_time//3600
m=(park_time-h*3600)//60
s=park_time-h*3600-m*60
P_time="%.0f%.0f points%.0f seconds"%(h,m,s)
consumption =((park_time)/3600)*5
self.balance -= consumption
print("The license plate number is:%sn parking time:%sn this consumption:%.2f yuan n card balance:%.2f yuan n"%(self.car_number,P_time, consumption, self.balance))
def __str__(self):if self.car_model=='0':
self.car_model="Car"
elif self.car_model=='1':
self.car_model="Small cards"
elif self.car_model=='2':
self.car_model="Medium card"
elif self.car_model=='3':
self.car_model="Kcal"return"%s %s %s %s %s %s"%(self.car_number,self.car_owner,self.contact_way,
self.car_color,self.car_model,self.entrance_time)
Create a class module setting_Manage.py about the management system
import time
classParkManage(object):"""Create a class about parking"""
def __init__(self,max_car=100,): #Define the maximum number of parked vehicles
self.max_car=max_car
self.car_list =[]
self.cur_car=len(self.car_list)
def info(self):""" #Display system function information"""print("""
―――――――――――――――――――――――――
|***Welcome to the vehicle management system***|
―――――――――――――――――――――――――
{1}{2}1) Add vehicle information{3}{2}{0}{2}2)Query vehicle information{3}{2}{0}{2}3)Display vehicle information{3}{2}{0}{2}4)Edit vehicle information{3}{2}{0}{2}5)Delete vehicle information{3}{2}{0}{2}6)Statistical vehicle information{3}{2}{0}{2}7)Exit system{3}{2}{1}""".format("-"*40,"="*40,"|"," "*16))
def add_car(self,car):"""#Add vehicle information"""
entrance_time = time.ctime()
car["entrance_time"]=entrance_time
for Car in self.car_list:if Car.car_number == car.car_number:print("The license plate information is wrong, please re-enter")breakelse:
self.car_list.append(car)print("The license plate number is%s's car was successfully put into the warehouse"%car.car_number)
def search_By_Number(self):"""#Search by license plate number"""
car_number=input("Please enter the license plate number you are looking for:")for car in self.car_list:if car.car_number==car_number:print(car)breakelse:print("No license plate number found%s vehicle"%car_number)
def search_By_Model(self):"""#Query by car model"""
car_model=int(input("(Car:0,Small card: 1, medium card: 2, large card: 3)nPlease enter the model you are looking for:"))if car_model in[0,1,2,3]:for car in self.car_list:if car_model==int(car.car_model):print(car)else:print("No relevant vehicle information found")else:print("The input is wrong, please re-enter")
def searchCar(self):"""#Find vehicle information"""print("""
1) Search by license plate number
2) Search by model
""")
search_chioce=input("Enter the method you are looking for:")if search_chioce =='1':
self.search_By_Number()
elif search_chioce=='2':
self.search_By_Model()else:print("The input is wrong, please re-enter")
def display(self):"""#Display vehicle information"""iflen(self.car_list)!=0:for car in self.car_list:print(car)else:print("Garage empty")
def change_Carinfo(self):"""#Modify vehicle information"""
car_number =input("Please enter the license plate number you are looking for:")for car in self.car_list:if car.car_number == car_number:
index=self.car_list.index(car)
change=int(input("(Modify the serial number of the information:n Owner 0,nContact information 1,n car color 2,n Model 3)nEnter the serial number of the information you want to modify:"))if change==0:
new_info=input("Enter new information:")
self.car_list[index].car_owner=new_info
print("The owner's name was modified successfully")break
elif change==1:
new_info=input("Enter new information:")
self.car_list[index].contact_way=new_info
print("Contact information modified successfully")break
elif change==2:
new_info=input("Enter new information:")
self.car_list[index].car_color=new_info
print("Car color modified successfully")break
elif change==3:
new_info=input("Enter new information:")
self.car_list[index].car_model=new_info
print("The model was modified successfully")breakelse:print("No license plate number found%s vehicle"% car_number)
def delete_car(self,car):"""Delete vehicle information"""
exit_time=time.ctime()
car["exit_time"]=exit_time
car.slot_card()
self.car_list.remove(car)print("The license plate number is%s's car two successfully deleted"%car.car_number)
def statistics(self):"""Statistical vehicle information"""
sedan_car_number=0
pickup_truck_number=0
middle_truck_number=0
super_truck_number=0for car in self.car_list:if car.car_model=='0':
sedan_car_number+=1
elif car.car_model=='1':
pickup_truck_number+=1
elif car.car_model=='2':
middle_truck_number+=1
elif car.car_model=='3':
super_truck_number+=1else:print("Car:%sn""Small cards:%sn""Medium card:%sn""Kcal:%sn"%(sedan_car_number,pickup_truck_number,middle_truck_number,super_truck_number))
Create main [function] (https://www.zalou.cn/tag/hanshu) in main_fun.py and run
import re
from setting_Car import Car
from setting_Manage import ParkManage
def check_car_number(car_number): #Determine whether the license plate number is legal
pattern = re.compile(u'[u4e00-u9fa5]?')
pattern1 = re.compile(u'[A-Z]+')
pattern2 = re.compile(u'[0-9]+')
match = pattern.search(car_number)
match1 = pattern1.search(car_number)
match2 = pattern2.search(car_number)if match and match1 and match2:return True
else:return False
def check_contact_way(contact_way): #Determine whether the phone number is legal
pattern = re.compile(u'1[3|4|5|6|7|8|9]d{9}$')
match = pattern.search(contact_way)if match:return True
else:return False
def main():
parkmanage=ParkManage()while True:
parkmanage.info()
choice=input("Please enter the function you want:")if choice=='1':
check_error_list=[]
car_number=input("Please enter the license plate number:")ifcheck_car_number(car_number):
car_owner=input("Please enter the owner's name:")
contact_way=input("Please enter the owner's contact information:")ifcheck_contact_way(contact_way):
car_color=input("Please enter car color:")
car_model=input("Please enter car model(Car:0,Small card: 1, medium card: 2, large card: 3):")
check_error_list=[car_number,car_owner,contact_way,car_color,car_model]for info in check_error_list: #Determine the completeness of the input information
if info=='':print("Incomplete input")breakelse:
car =Car(car_number, car_owner, contact_way, car_color, car_model)
parkmanage.add_car(car)else:print("Invalid phone number")else:print("License plate number is illegal")
elif choice=='2':
parkmanage.searchCar()
elif choice =='3':
parkmanage.display()
elif choice=='4':
parkmanage.change_Carinfo()
elif choice=='5':
car_number =input("Enter the license plate number of the vehicle you want to delete:")for car in parkmanage.car_list:if car.car_number == car_number:
parkmanage.delete_car(car)breakelse:print("No license plate number found%s vehicle"%(car_number))
elif choice=='6':
parkmanage.statistics()
elif choice=='7':print("Welcome to use next time! ! !")exit()else:print("Please enter the correct option")if __name__ =='__main__':main()
The above is the whole content of this article, I hope it will be helpful to your study, and I hope you can support website (zalou.cn).
Recommended Posts