Skip to content

Commit 16e8e22

Browse files
authored
Add files via upload
1 parent 0437dba commit 16e8e22

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Arrays/Average_Calculator.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'''
2+
Aim: To calculate average of all the distinct integers.
3+
4+
'''
5+
6+
def average(array):
7+
# getting all unique numbers
8+
p = set(array)
9+
# calculating the total number of elements
10+
s = len(p)
11+
# computing the average
12+
ans = sum(p)/s
13+
# printing the result
14+
print('Average is:',ans)
15+
16+
# getting the input
17+
arr = input('Enter numbers: ').strip().split()
18+
# converting elements into integer type for calculating average
19+
arr_int = []
20+
for i in arr:
21+
arr_int.append(int(i))
22+
# calling function to compute the average
23+
average(arr_int)
24+
25+
'''
26+
27+
COMPLEXITY:
28+
29+
Time Complexity -> O(1)
30+
Space Complexity -> O(N)
31+
32+
Sample Input:
33+
Enter numbers: 5 3 1 2 3 4 5
34+
35+
Sample Output:
36+
Average is: 3.0
37+
38+
Explanation:
39+
All unique integers --> 1 2 3 4 5
40+
Total count --> 5
41+
Average --> (1+2+3+4+5)/5 = 3.0
42+
43+
'''

0 commit comments

Comments
 (0)