I want to save the output as a text file on my system. The name of the output file should get from the user in command prompt.
output = input("Enter a name for output file:") my_file = open('/output.txt', "w") for i in range(1, 10): my_file.write(i) Is this correct way of doing??
output.txt. If you want to use the user's input as the file name, you'll have to pass something likeoutput + '.txt'to theopenfunction.