print('Vehicle Inventory System')
class Automobile:
def __init__(self):
self._make = ''
self._model = ''
self._year = 0
self._color = ''
self._mileage = 0
def addVehicle(self):
try:
self._make = input('Enter vehicle make: ')
self._model = input('Enter vehicle model: ')
self._year = int(input('Enter vehicle year: '))
self._color = input('Enter vehicle color: ')
self._mileage = int(input('Enter vehicle mileage: '))
return True
except ValueError:
print('Please try entering vehicle information again using only whole numbers for mileage and year')
return False
def __str__(self):
return '\t'.join(str(x) for x in [self._make, self._model, self._year, self._color, self._mileage])
class Inventory:
def __init__(self):
self.vehicles = []
def addVehicle(self):
vehicle = Automobile()
if vehicle.addVehicle() == True:
self.vehicles.append(vehicle)
print ()
print('This vehicle has been added, Thank you')
def viewInventory(self):
print('\t'.join(['','Make', 'Model','Year', 'Color', 'Mileage']))
for idx, vehicle in enumerate(self.vehicles) :
print(idx + 1, end='\t')
print(vehicle)
inventory = Inventory()
while True:
print('#1 Add Vehicle to Inventory')
print('#2 Delete Vehicle from Inventory')
print('#3 View Current Inventory')
print('#4 Update Vehicle in Inventory')
print('#5 Export Current Inventory')
print('#6 Quit')
userInput=input('Please choose from one of the above options: ')
if userInput=="1":
inventory.addVehicle()
elif userInput=='2':
if len(inventory.vehicles) < 1:
print('Sorry there are no vehicles currently in inventory')
continue
inventory.viewInventory()
item = int(input('Please enter the number associated with the vehicle to be removed: '))
if item - 1 > len(inventory.vehicles):
print('This is an invalid number')
else:
inventory.vehicles.remove(inventory.vehicles[item - 1])
print ()
print('This vehicle has been removed')
elif userInput == '3':
if len(inventory.vehicles) < 1:
print('Sorry there are no vehicles currently in inventory')
continue
inventory.viewInventory()
elif userInput == '4':
if len(inventory.vehicles) < 1:
print('Sorry there are no vehicles currently in inventory')
continue
inventory.viewInventory()
item = int(input('Please enter the number associated with the vehicle to be updated: '))
if item - 1 > len(inventory.vehicles):
print('This is an invalid number')
else:
automobile = Automobile()
if automobile.addVehicle() == True :
inventory.vehicles.remove(inventory.vehicles[item - 1])
inventory.vehicles.insert(item - 1, automobile)
print ()
print('This vehicle has been updated')
elif userInput == '5':
if len(inventory.vehicles) < 1:
print('Sorry there are no vehicles currently in inventory')
continue
f = open('vehicle_inventory.txt', 'w')
f.write('\t'.join(['Make', 'Model','Year', 'Color', 'Mileage']))
f.write('\n')
for vechicle in inventory.vehicles:
f.write('%s\n' %vechicle)
f.close()
print('The vehicle inventory has been exported to a file')
elif userInput == '6':
print('Goodbye')
break
else:
print('This is an invalid input. Please try again.')
没有合适的资源?快使用搜索试试~ 我知道了~
Vehicle Inventory System Project in Python.zip
共1个文件
py:1个
0 下载量 61 浏览量
2023-11-03
16:49:59
上传
评论
收藏 1KB ZIP 举报
温馨提示
Vehicle Inventory System Project in Python.zip
资源推荐
资源详情
资源评论
收起资源包目录
Vehicle Inventory System Project in Python.zip (1个子文件)
Vehicle Inventory System Project in Python
index.py 4KB
共 1 条
- 1
资源评论
xiaoshun007~
- 粉丝: 3849
- 资源: 3131
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功