Код: Выделить всё
# Option 2
elif option == "2":
# checkTime = input function and use timedelta for correct format
checkTime = input('Please enter a time in the form "00:00:00"')
hour, minute, second = checkTime.split(":")
rtime = datetime.timedelta(hours=int(hour), minutes=int(minute), seconds=int(second))
# For all packages print status at certain time
for i in range(40):
pack = myHash.search(i + 1)
print(pack)
# At Hub
if rtime < pack.timeLeftHub0:
print('At Hub')
elif rtime == pack.time_delivered:
print('Delivered on Truck ' + str(pack.truck))
elif rtime > pack.time_delivered:
print('Delivered on Truck ' + str(pack.truck))
else:
print('En Route on Truck ' + str(pack.truck))
- У меня также добавлен ввод с именем checkPackage (чтобы пользователь мог сказать, что статус пакета, который они хотят, введя идентификатор пакета)
- вместо «для i в диапазоне» мне нужно что-то, чтобы связать идентификатор пакета, введенный в checkPackage, с объектом пакета в моей хеш-таблице .
Код: Выделить всё
# Option 3
elif option == "3":
checkPackage = input('Please enter a package using its package ID')
checkTime = input('Please enter a time in the form "00:00:00"')
hour, minute, second = checkTime.split(":")
rtime = datetime.timedelta(hours=int(hour), minutes=int(minute), seconds=int(second))
for package_id in checkPackage:
pack = myHash.search(package_id)
if rtime < pack.timeLeftHub0:
pack.status = 'At Hub'
print(str(pack.package_id) + ' package status at ' + str(rtime) + ' = ' + str(pack.status))
elif rtime == pack.time_delivered:
pack.status = 'Delivered'
print(str(pack.package_id) + ' package status at ' + str(rtime) + ' = ' + str(pack.status))
elif rtime > pack.time_delivered:
pack.status = 'Delivered'
print(str(pack.package_id) + ' package status at ' + str(rtime) + ' = ' + str(pack.status))
else:
pack.status = 'En Route'
print(str(pack.package_id) + ' package status at ' + str(rtime) + ' = ' + str(pack.status))
Код: Выделить всё
Choose an option (1,2,3, or 4): 3
Please enter a package using its package ID14
Please enter a time in the form "00:00:00"10:00:00
Traceback (most recent call last):
File "C:\Users\alecc\PycharmProjects\pythonProject\Main.py", line 431, in
if rtime < pack.timeLeftHub0:
^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'timeLeftHub0'
Подробнее здесь: https://stackoverflow.com/questions/783 ... ugh-this-v