我对 Python 编程比较陌生,使用 Python 3.x,并且正在开发一个理发店 POS 系统,管理员将有权添加服务及其相应的价格。我正在使用 Pretty Table 库来实现打印出带有 serviceID、service 和 price 的表。
这是我的代码:
from prettytable import PrettyTable
import random
serviceID = []
services = []
price = []
x = PrettyTable()
x.add_column("ServiceID",[serviceID])
x.add_column("Service", [services])
x.add_column("Price", [price])
while True:
try:
ID = random.randint(1,90000) #range high to lower probability of non-uniqueness
serviceID.append(ID) #Generates unique ID for each service
prompt1 = input("Please add a service name to the list\n")
services.append(prompt1)
prompt2 = input("Please enter a price for the service\n")
prompt2 == int(prompt2)
price.append(prompt2)
print(x)
except ValueError:
print("Please enter valid type")
continue
当我输入第一个服务和价格时,输出是:
+-----------+---------+--------+
| ServiceID | Service | Price |
+-----------+---------+--------+
| [9880] | ['box'] | ['90'] |
+-----------+---------+--------+
当我输入第二项服务和价格时,输出是这样的:
+---------------+-----------------+--------------+
| ServiceID | Service | Price |
+---------------+-----------------+--------------+
| [9880, 47612] | ['box', 'trim'] | ['90', '80'] |
+---------------+-----------------+--------------+
我希望输出是这样的:
+---------------+-----------------+--------------+
| ServiceID | Service | Price |
+---------------+-----------------+--------------+
| 9880 | box | 90 |
| 47612 | trim | 80 |
+---------------+-----------------+--------------+
有谁知道如何实现这一目标?任何帮助,将不胜感激。