So hello everybody.
I recently had a problem which I tried to use python included file functions and stuff
i tried making a text editor which was when i encountered a problem
i tried to make the txteditor like this:
one = input()
two = input()
three = input()
four = input()
five = input()
six = input()
seven = input()
eight = input()
nine = input()
ten = input()
f= open("guru99.txt","w+")
for i in range(10):
f.write(one, two, three, four, five, six, seven, eight, nine, ten)
f.close()
but it give the error :
f.write(one, two, three, four, five, six, seven, eight, nine, ten)
TypeError: TextIOWrapper.write() takes exactly one argument (10 given)
can aanybody help with this?
>Solution :
You’re passing in each number as a separate argument to f.write(), except that function only expects a single parameter.
You can do this by first joining all your inputs into a single variable, such as a string, and then passing that in. This is called concatenation:
joinedInputs = one + two + three + four + ... + ten
f.write(joinedInputs)
However, this is a somewhat inefficient way of doing it, and you may want to research something like a list:
inputs = []
for i in range(10):
userInput = input()
inputs.append(userInput)
Then you can simply loop over all of them and join them to a single string, which can be done a few ways, for example by looping over each element in the list and concatenating it as above.