Open reading and averaging text files python

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Open reading and averaging text files python



Hi so i'm currently trying to write a code that asks for a number of days and then opens multiple text files(temps1.txt etc), reads them, sorts them into dictionarys with an average and then prints it out. However some of the averages have an extreme amount of decimal spots


f =
ans = int(input('How many days of data do you have? '))
#figure out how to open certain files
for file_num in range(1, (ans+1)):
file_name = "temps" + str(file_num) + ".txt"
temps = open(file_name)
for line in temps:
room, num = line.strip('n').split(',')
num = int(num)
#may need to be 4* however many times it appears
num = num/(4*ans)
f[room] = f.get(room, 0) + num

print('Average Temperatures:')
for x in f:
print (x + ':',f[x])



i have an example for a room called bedroom (all the bedrooms in the text files average) and the average is 26.0 however it prints out as 26.000000000000004 how do i stop it doing this?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard