Python Array Find Average Temperature of Week Program
# Write a Python program # to input daily temperatures for # a week and find average temperatur # of week # Perfect Python Programming Tutorials # Author : www.EasyCodebook.com (c) # Actual Program starts here import array a = array.array('d', []) n = 7 print('Enter 7 Daily Temperature for a Week:') for i in range(n): item= float(input("Enter Temperature of Day:"+str(i+1)+': ')) a.append(item) sum=0.0 for item in a: sum = sum + item avg = sum / 7.0 print('Temperature of Week are:', end=' ') for item in a: print(item, end=' ') print('\nAverage Temperature of Week is:'+'{:.2f}'.format(avg))
Output:
Enter 7 Daily Temperature for a Week: Enter Temperature of Day:1: 23 Enter Temperature of Day:2: 24 Enter Temperature of Day:3: 23 Enter Temperature of Day:4: 21 Enter Temperature of Day:5: 22 Enter Temperature of Day:6: 22.6 Enter Temperature of Day:7: 21.8 Temperature of Week are: 23.0 24.0 23.0 21.0 22.0 22.6 21.8 Average Temperature of Week is:22.49