Just improving the answer already given, some tips.
You can use the with
when defining the file Handler in a proper scope and so need not close it from the arquivo.close()
in the end.
with open('escala.txt', 'w') as arquivo:
for i in range(0, 101):
var = (i * 2000) / 100
arquivo.write('Temperature is {}oC converted is {}\n'.format(i, var))
Another tip is to use the format()
to mount his string as well as more intelligent than the str()
, allows better control of the presentation (number of decimals, zero on the left etc).
Finally a mathematical hint, multiplying a number by 2000 and then dividing by 100 is the same thing as just multiplying by 20, one less operation at the end.
The . white there, right? wasn’t supposed to be . write? and in the end, archive2.close() was supposed to be.close file()
– JassRiver
truth I’m sorry, it is possible to edit the publication?
– Eric Levinski Kirsten
.write takes a string, so vc will have to format, set Iver using python 3.6 or higher use fstring, f'Temperature is:{i} °C converted is: {var} n'
– Elton Nunes
thanks for the tip!
– Eric Levinski Kirsten