我必须用 Python 为 UI 创建代码。我基本上有 4 个选项,当然每个选项都会打印出想要的结果。代码如下。我缺少一行打印内容,但我向我的老师询问了这一点。我还需要知道什么 - 如何测试我的 UI 代码以查看是否能得到我想要的结果?
getPackageStatus = True
while getPackageStatus:
# Options for UI
print("\nWhat Would You Like to Check Today?")
print("1. All package statuses and Total Truck mileage")
print("2. Status of all Packages at a given time")
print("3. Single package status with a given time")
print("4. Exit the program")
# Go through each option, describing outcomes
option = input("Choose an option (1,2,3, or 4): ")
# Option 1
if option == "1":
for i in range(40):
print(myHash.search(i + 1) + str(t1.mileage + t2.mileage + t3.mileage))
# Option 2
elif option == "2":
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))
if checkTime < pkg1.timeLeftHub0:
pkg1.status = 'At Hub'
elif checkTime == pkg1.time_delivered:
pkg1.status = 'Delivered'
elif checkTime > pkg1.time_delivered:
pkg1.status = 'Delivered'
else:
pkg1.status = 'En Route'
# Need help writing the print statement that will print out all pkg1.status for all packages. I know it will involve strings and a myHash.search method so each package ID will be associated with its status at checkTime
# Option 3
elif option == "3":
checkPackage = input('Please enter a package using its package ID')
for package_id in checkPackage:
pkg1 = myHash.search(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))
if checkTime < pkg1.timeLeftHub0:
pkg1.status = 'At Hub'
print(str(pkg1.package_id) + 'package status at ' + str(checkTime) + ' = ' + str(pkg1.status))
elif checkTime == pkg1.time_delivered:
pkg1.status = 'Delivered'
print(str(pkg1.package_id) + 'package status at ' + str(checkTime) + ' = ' + str(pkg1.status))
elif checkTime > pkg1.time_delivered:
pkg1.status = 'Delivered'
print(str(pkg1.package_id) + 'package status at ' + str(checkTime) + ' = ' + str(pkg1.status))
else:
pkg1.status = 'En Route'
print(str(pkg1.package_id) + 'package status at ' + str(checkTime) + ' = ' + str(pkg1.status))
# Option 4
elif option == "4":
getPackageStatus = False
我不知道如何测试这个并且在网上找不到任何东西
我希望我没有误解你的问题,但是你应该能够运行你的Python程序并输入1、2、3和4,然后看看它打印出来的内容。