304 North Cardinal St.
Dorchester Center, MA 02124
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.
Complete the average function in the editor below.
average has the following parameters:
The first line contains the integer, , the size of .
The second line contains the space-separated integers, .
STDIN Function ----- -------- 10 arr size N = 10 161 182 161 154 176 170 167 171 170 174 arr = [161, 181, ..., 174]
Here, set ([154, 161, 167, 170, 171, 174, 176, 182]) is the set containing the distinct heights. Using the sum() and len() functions, we can compute the average.
n = float(raw_input()) plant = set() sum_p = 0 for x in raw_input().split(' '): if x not in plant: plant.add(x) sum_p += float(x) print sum_p/float(len(plant))
def average(array): return sum(set(array))/len(set(array))
def average(array): s = set(array) return sum(s)/len(s)
def average(array): # your code goes here x=set(array) return float(sum(x)/len(x))
In our experience, we suggest you solve this Introduction to Sets Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
Introduction to Sets problem is available on Hacker Rank for Free, if you are stuck anywhere between a compilation, just visit Queslers to get Introduction to Sets Hacker Rank Solution
I hope this Introduction to Sets Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.
This Problem is intended for audiences of all experiences who are interested in learning Programming in a business context; there are no prerequisites.
More Hacker Rank Problem & Solutions >>
Staircase Hacker Rank Solution
A Very Big Sum Hacker Rank Solution
Diagonal Difference Hacker Rank Solution
Nested Lists Hacker Rank Solution