+ 1
Whats wrong with this code? The error was : TypeError: write() takes exactly one argument (6 given)
I am trying to make a code that finds the min and max of two numbers and then crates a text file writing these numbers and today's date. Can you help me please? https://code.sololearn.com/c2Z1rAQVsNa2
4 Réponses
+ 3
Elias, I tried to make your code a bit more clear and readable. But i ended up with a reworked version of your code. There has been several issues, that not all are visible at the first view.
- You need only import of module datetime
- Naming of variables has been max(confusion) 😉, as You used names like max or min, which are also used as built-in names
- Big issue and difficult to find: You used the input string for comparison instead of numerical values. This lead to a result, that 2 is bigger than 10. This gave no error!
So check your code with the reworked version: https://code.sololearn.com/c529JYdE52FY/?ref=app
+ 2
The issue is, that file.write() can take only one argument, but there are 6 arguments given. This can be changed by using an f-string.
But the firts thing you have to do is, to correct variable names like min and max. These names should never be used, because they are also names for a built-in functions.
+ 1
f.write(" statements") accepts only 1 argument ,all statements inside double quotes ,what you are doing created 6 arguments so it says only 1 argument
You can do something like this
f.write("\"The maximum was\",max,\" and the minimum \",min, \"on\",today")
or like this
f.write(" 'The maximum was ',max, 'and the minimum ',min, 'on',today ")
+ 1
@Lothar Thanks a lot! Your code helped me understand many things!