My task is to be able to generate a unique number for every input a user gives my program and save this number along with their input in a file I called customer_references. I want the file to present something like this :
Case number: 1 Issue: My issue is....
Case number: 2 Issue: My phone is...
Case number: 3 Issue: ...... (etc.)
And also need to be able to print the case number for the user to know on python. I tried using randint but this wasn't efficient enough as the case number has a chance of being repeated for a different user
This is my unfinished code :
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()
A randint
is not sufficiently large for the purpose of unique id. You should use the uuid
module to generate a UUID number, which, although random, can be safely considered unique for all practical purposes