file = open("filehandling_ex.txt",'w+')
temperatures=[10,-20,-289,100]
def c_to_ff(c):
if c < -273.15:
return "Cannot write. " + str(c) + " is under -273.15"
else:
f = c*9/5 + 32 # celisus to farenheit
return f
for temp in temperatures:
result = str(c_to_ff(temp))+"\n"
file.write(result)
print(c_to_ff(temp))
file.close()
# close 없이 쓰려면 with open 사용
with open("filehandling_ex.txt", 'a+') as file:
file.seek(0)
content = file.read()
file.write("\nAWESOME !")
Python def 1
기억상실 보존용
댓글 없음:
댓글 쓰기