【发布时间】:2017-01-18 15:54:48
【问题描述】:
我的任务是能够为用户提供给我的程序的每个输入生成一个唯一编号,并将此编号与他们的输入一起保存在我称为 customer_references 的文件中。 我希望文件呈现如下内容:
案例编号:1 问题:我的问题是......
案例编号:2 问题:我的手机是...
案例编号:3 问题: ...... (等等)
并且还需要能够在 python 上打印案例编号以便用户知道。 我尝试使用 randint,但这不够有效,因为案例编号有可能为不同的用户重复
这是我未完成的代码:
def issue_details():
#prints aplogy message for not being able to find a solution
print("Sorry we were unable to provide a suitable solution")
#Takes further information on details of issue from the user
issue = input("Please explain your issue in as much detail so we can direct you to a technician: ")
#opens the file I created to store the customers details to append the issue into it.
customer_file = open("Customer_references.txt","a")
#inputs the issue into the text file
customer_file.write(issue)
#Here I need to generate the case number and add it to my file beside the users issue
#The case number must always be unique
print("Thank you for your cooperation. Contact us on 0844558888 and give the technician your reference number so we can try help you\n", "Your reference is: ",#case_number )
customer_file.close()
【问题讨论】:
-
所以问题的编号必须在所有客户中都是唯一的?您正在编写的文件包含所有这些问题,对吗?然后,如果这是家庭作业,我会读取先前写入的文件的最后一行,确定该案例编号,然后从那里递增(案例 1、案例 2 等)。如果这不是家庭作业和真实系统,那么我将使用数据库(sqlite 启动)。