Python implements car management system

The examples in this article share the specific code of python to implement the car management system for your reference. The specific content is as follows

1、 Define the vehicle class. The attributes include the 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 class 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. The car waits on the sidewalk outside the door in the parking lot. 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 the button when it leaves the parking lot. It pays for the length of time it stays.

**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 repeated numbers 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 vehicle types, according to arrival time [Statistics] (https://www.zalou.cn/tag/tongji), etc.

**Implementation code: **

import datetime
classCarMessage(object):
def __init__(self, num, owner, color, type, connect, money, endtime):
# Car attributes
self.num = num
self.color = color
self.type = type
self.owner = owner
self.connect = connect
self.money = money
self.entime = endtime
def __str__(self):print('number plate:<%s Owner:<%s color:<%s models:<%s Contact:<%s balance:<%s Parking time:<%s  '%(self.num, self.owner, self.color, self.type, self.connect, self.money, self.entime))classPark(object):
def init(self): #Initialize the vehicle in the parking lot
self.car_list.append(CarMessage('001','python','black','Kcal','123456789',34, datetime.datetime.now()))
self.car_list.append(CarMessage('002','hello','black','Car','123456789',87, datetime.datetime.now()- datetime.timedelta(minutes=10)))
self.car_list.append(CarMessage('003','java','White','Car','123456789',55, datetime.datetime.now()- datetime.timedelta(hours=1)))
self.car_list.append(CarMessage('004','westos','black','Small cards','123456789',60, datetime.datetime.now()- datetime.timedelta(days=2)))
self.car_list.append(CarMessage('005','root','White','Medium card','123456789',24, datetime.datetime.now()- datetime.timedelta(minutes=60)))
def __init__(self):
self.max_car =200
self.car_list =[]
self.cur_car =len(self.car_list)
def Menu(self):
self.init()while True:print("""
Parking lot management system
1 )parking
2 )Pick up the car
3 ) Balance inquiry
4 ) Shows that the vehicle has been stored
5 )Inquire
6 ) Edit vehicle information
7 )drop out
""")
choice =input("Please enter your choice:")if choice =='1':
self.park()
elif choice =='2':
self.exit()
elif choice =='3':
car =input("Please enter the license plate number:")
self.pay(car)
elif choice =='4':for i in self.car_list:
CarMessage.__str__(i)
elif choice =='5':
self.find()
elif choice =='6':  #Edit vehicle information
self.edit()
elif choice =='7':exit(0)else:print('Please enter the correct option! ! !')
def park(self):if self.cur_car<self.max_car:
car_num =input('Please enter your license plate number:')
res = self.check(car_num) #Determine whether the license plate has a parking record
if res is None:
self.car_list.append(CarMessage(car_num,input('Owner:'),input('colour:'),input('Model<Small cars, small trucks, medium trucks and large trucks:'),input('contact details:'),int(input('Balance')), datetime.datetime.now()))print('Car can enter')else:print('The vehicle is already inside the parking lot')else:print('The parking space is full, no parking')
def exit(self):
car_num =input("Please enter your license plate number:")
res = self.check(car_num)if res is not None:
self.pay(res)
self.car_list.remove(res)print('Safe journey,Safe travel')else:print('Your vehicle is not in the parking lot, please notify the administrator!')
def pay(self,car):
# res = self.check(car)
money =(datetime.datetime.now()- car.endtime).seconds /60print("current balance:%s"%(money))while True:if car.money  = money: #Determine whether the balance is enough to pay
car.money -= money
print('Automatic payment%s success'%(money))breakelse:print('Please recharge if the balance is insufficient')
car.money +=int(input('Recharge amount:'))print('Top up successfully')
def check(self,car_num):for i in self.car_list:if car_num == i.num:return i
else:return None
def find(self):while True:print('''
1 ) Query by license plate
2 ) Query according to the model
3 )return
''')
choice =input("Please enter your choice:")if choice =='1':
num =input('number plate:')
res = self.check(num)if res is not None:
CarMessage.__str__(res)else:print("No such car found!")
elif choice =='2':
type =input("Model<Small cars, small trucks, medium trucks and large trucks:")if type in['Car','Small cards','Medium card','Kcal']:for i in self.car_list:if i.type == type:
CarMessage.__str__(i)else:print('does not exist%s this model'%(type))
elif choice =='3':breakelse:print('Please enter the correct option n')
def edit(self):  #Change vehicle information
num=input('Please enter the license plate number:')
res = self.check(num)if res is not None:
CarMessage.__str__(res)print('Information modification: n License plate number:%s'%(num))
res.owner =input('Owner:')
res.clor =input('colour:')while True:
type =input("Model<Small cars, small trucks, medium trucks and large trucks:")if type in['Car','Small cards','Medium card','Kcal']:
res.type = type
breakelse:print('does not exist%s this model,Please re-enter n'%(type))
res.connect =input('contact details:')
res.money =int(input('Balance:'))
res.entime = datetime.datetime.strptime(input('Time to enter the parking lot(eg:2018-05-21 11:14:10):'),'%Y-%m-%d %H:%M:%S')print('Information modified successfully...')else:print('No license plate%s vehicle information'%(num))
p =Park()
p.Menu()

Function 3 has some problems temporarily, and it is still learning.

The above is the entire content of this article, I hope it will be helpful to your study, and I hope you can support website (zalou.cn).

Articles you may be interested in:

Recommended Posts

Python implements car management system
Python implements a simple business card management system
Python implements student performance evaluation system
Python realizes business card management system
Python business card management system development
Python version business card management system
Implementation of python student management system
Python implements the actual banking system
centos system management
Python realizes the development of student management system
Use python to realize business card management system
Implementation of business card management system with python
Python implements Super Mario
Python implements tic-tac-toe game
Python implements tic-tac-toe game
Python implements man-machine gobang
Python implements Tetris game
Python implements image stitching
Python implements minesweeper game
Python implements scanning tools
Context management in Python
Python crawler gerapy crawler management
Python implements threshold regression
Python implements minesweeper games
Python implements electronic dictionary
Python implements guessing game
Centos system process management
Implementation of business card management system based on python
Python implements simple tank battle
Python implements udp chat window
Python implements WeChat airplane game
Python implements word guessing game
Python runtime exception management solution
Python implements a guessing game
Python implements digital bomb game
Python implements TCP file transfer
Python numpy implements rolling case
Python implements simple tic-tac-toe game
Python implements password strength verification
Python realizes face sign-in system
Python implements code block folding
Python implements panoramic image stitching
Python implements SMTP mail sending
Python implements multi-dimensional array sorting
How Python implements FTP function
Python implements mean-shift clustering algorithm
Python implements verification code recognition
Python implements gradient descent method
Python implements text version minesweeper
Python implements image stitching function
Python implements the brick-and-mortar game
How Python implements the mail function
Python simply implements the snake game
Python3 implements the singleton design pattern
Python implements exchange rate conversion operations
Python implements string and number splicing
Python implements ten classic sorting algorithms
Python implements a universal web framework
Python implements 126 mailboxes to send mail
Python implements AI face change function
Python realizes express price query system