Python Forum

Full Version: Saving the results from an input in a txt. file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im currently working on a school project where I have to make a multiplication table where you put in a value for the size you want the table to be. I want my program to save the results to "gangetabell.txt", but I cant seem to figure out how to save the results to the file. My problem is how to put the code as an argument inside the write() function.

Here is the code:

print("\t\tGangetabell\n")

n =int(input('Vennligst skriv inn et tall: '))
for row in range(1,n+1):
for col in range(1,n+1):
print(row*col, end="\t")
print('\n')
saveFile = open('gangetabell.txt', 'w')
saveFile.write()
saveFile.close()



And this is the error I get:

Traceback (most recent call last):
File "C:/Users/Erlend/PycharmProjects/python_2/oppg_2.py", line 9, in <module>
saveFile.write()
TypeError: write() takes exactly one argument (0 given)

Process finished with exit code 1
Since you have no indentation, it is hard to determine what your code actually looks like.  However, the "error" code is pretty explicit. You are trying to write to a file without saying what it is you want to write.
file_object.write("You put here what you want to be written into the file.")