-4

I am creating a troubleshooting system, where if an answer cannot be given to the user, I assign them a case number through the randint function. I am struggling to save this random number by placing it in an external database for later use and reference. Can someone help me by using the method of reading and writing from files?

from random import randint
print('sorry I cannot help you',randint(0,100000))
ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57
jeff.123
  • 3
  • 4

1 Answers1

2
with open("Output.txt", "w") as text_file:
    some_rand_num = randint(0, 100000)
    print('sorry I cannot help you',some_rand_num)
    text_file.write("sorry I cannot help you %s" % some_rand_num)

For reference: https://docs.python.org/2/tutorial/inputoutput.html

manvi77
  • 536
  • 1
  • 5
  • 15
  • Do I have to save the file where I want the numbers to be saved as Output.txt?? – jeff.123 Mar 04 '17 at 16:28
  • Yes, you change file name and also the location to save wherever you want! – manvi77 Mar 04 '17 at 16:33
  • I done this but it is not printing in the file called Output :( do i have to do it in notepad? – jeff.123 Mar 04 '17 at 16:40
  • In general, the Output.txt file is created in the same location of your python script unless you specify the location. Likewise, if your python script is on Desktop, the Output.txt file is also created on Desktop. – manvi77 Mar 04 '17 at 17:13