-3

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()
Ari Gold
  • 1,528
  • 11
  • 18
Hiba.A
  • 11
  • 1
  • 3
  • So the number of the issue has to be unique across all customers? The file you are writing contains all these issues right? Then, if this is homework, I would read the last line of the file previously written to, determine that case number, then increment from there (case 1, case 2, etc). If this is not for homework and for a real system then I would use a database (sqlite to start). – djhoese Jan 18 '17 at 16:00

1 Answers1

1

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

blue_note
  • 27,712
  • 9
  • 72
  • 90