File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
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
+ '''
You can’t perform that action at this time.
0 commit comments