-->

Introduction to Sets - Hacker Rank Solution | Apna Hindi Tech | Python Hacker Rank




Hello Friends 

рдЖрдЬ рд╣рдо рдЖрдкрдХो Hacker Rank рдкрд░ Introduction to Sets рдХा рдХंрдк्рд▓ीрдЯ рд╕ॉрд▓्рдпूрд╢рди рдмрддाрдПंрдЧे рд╡рд╣ рднी рдЖрд╕ाрди рднाрд╖ा рдоें। рддो рджोрд╕्рддों рдЪрд▓िрдП рдЬाрдирддे рд╣ैं рд╕ॉрд▓्рдпूрд╢рди ।


Set Tutorial In Python :-



Problem:- Introduction to Sets -Hacker Rank Solution


Task :-

Now, let's use our knowledge of sets and help Mickey.

Ms. Gabriel Williams is a botany professor at District College. One day, she asked her student Mickey to compute the average of all the plants with distinct heights in her greenhouse.

Formula used:





Input Format

The first line contains the integer, , the total number of plants.
The second line contains the  space separated heights of the plants.


Constraints :-


Output Format :-

Output the average height value on a single line.


Sample Input :-

10
161 182 161 154 176 170 167 171 170 174



Sample Output :-

169.375


Explanation :-

Here, set is the set containing the distinct heights. Using the sum() and len() functions, we can compute the average.






Solution :-
def average(array):
    # your code goes here
    s=set()
    s.update(array)
    return(sum(s)/len(s))
        
if __name__ == '__main__':
    n = int(input())
    arr = list(map(intinput().split()))
    result = average(arr)
    print(result)


Video Tutorial :-










Other Hacker Rank Solutions










DISCLAIMER:-
The above hole problem statement is given by hackerrank.com but the solution is generated by the  Apna Hindi Tech authority if any of the query regarding this post or website fill the following contact form.

......Thank YouЁЯШК......



рдпрд╣ рднी рдкрдв़ें

Post a Comment