{"id":5419,"date":"2023-08-05T10:29:41","date_gmt":"2023-08-05T10:29:41","guid":{"rendered":"https:\/\/assignmenttask.com\/answers\/?p=5419"},"modified":"2024-01-16T11:14:35","modified_gmt":"2024-01-16T11:14:35","slug":"mean-median-and-mode","status":"publish","type":"post","link":"https:\/\/assignmenttask.com\/answers\/mean-median-and-mode\/","title":{"rendered":"Mean, Median and Mode"},"content":{"rendered":"<h2><strong>Mean, Median and Mode<\/strong><\/h2>\n<p>&nbsp;<\/p>\n<p>Given a list of integers, write a program to print the mean, median and mode.<\/p>\n<p><strong>Mean &#8211;<\/strong> The average value of all the numbers.<\/p>\n<p><strong>Median &#8211;<\/strong> The mid-point value in the sorted list.<\/p>\n<p><strong>Mode &#8211;<\/strong> The most common value in the list.<\/p>\n<p>&nbsp;<\/p>\n<p>If multiple elements with same frequency are present, print all the values with same frequency in increasing order. Input<\/p>\n<p>The input will be a single line containing space-separated integers. Output<\/p>\n<p>The first line of output should contain the mean, round off the value to 2 decimal places.<\/p>\n<p>The second line of output should contain the median, round off the value to 2 decimal places.<\/p>\n<p>The third line of output should contain the mode.<\/p>\n<p>Mean should always be a float value.<\/p>\n<p>Median should be a float value when there are even number of elements, otherwise should be an integer value.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Sample Input 1<\/strong><\/p>\n<p>2 4 5 6 7 8 2 4 5 2 3 8<\/p>\n<p><strong>Sample Output 1<\/strong><\/p>\n<p><strong>Mean:<\/strong> 4.67<\/p>\n<p><strong>Median:<\/strong> 4.5<\/p>\n<p><strong>Mode:<\/strong> 2<\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Answers: <\/strong><\/h3>\n<p>def get_median(arg_list):<\/p>\n<p>arg_list.sort()<\/p>\n<p>size = len(arg_list)<\/p>\n<p>if size %2 == 1:<\/p>\n<p>return arg_list[size\/\/2]<\/p>\n<p>else:<\/p>\n<p>return (arg_list[size\/\/2] + arg_list[size\/\/2 -1])\/2<\/p>\n<p>&nbsp;<\/p>\n<p>def get_mean(arg_list):<\/p>\n<p>sum_list = 0<\/p>\n<p>for i in arg_list:<\/p>\n<p>sum_list +=i<\/p>\n<p>return round(sum_list\/len(arg_list), 2)<\/p>\n<p>&nbsp;<\/p>\n<p>def get_mode(arg_list):<\/p>\n<p>mode_list = sorted(set(user_list), key=user_list.count,reverse=True)<\/p>\n<p>mode_max = user_list.count(mode_list[0])<\/p>\n<p>mode_res = []<\/p>\n<p>for i in mode_list:<\/p>\n<p>if user_list.count(i) &lt; mode_max:<\/p>\n<p>break<\/p>\n<p>mode_res.append(i)<\/p>\n<p>return sorted(mode_res)<\/p>\n<p>&nbsp;<\/p>\n<p>user_str = input(&#8216;Enter a string of integers separated by a space: &#8216;)<\/p>\n<p>user_list = [int(i) for i in user_str.split()]<\/p>\n<p>print(&#8216;Mean :&#8217;, get_mean(user_list))<\/p>\n<p>print(&#8216;Median :&#8217;, get_median(user_list))<\/p>\n<p># Displaying mode list values separated by a space<\/p>\n<p>print(&#8216;Mode :&#8217;, *get_mode(user_list))<\/p>\n<p>&nbsp;<\/p>\n<h3 style=\"text-align: center;\"><strong>Looking for Solutions?<\/strong><\/h3>\n<p style=\"text-align: center;\">Get the best assignment assistance from experts.<\/p>\n<p><a href=\"https:\/\/assignmenttask.com\/order-now.php\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1261 size-full lazyload\" title=\"Order Now\" data-src=\"https:\/\/assignmenttask.com\/answers\/wp-content\/uploads\/2019\/04\/Order-Your-Assignment.jpg\" alt=\"Order-Your-Assignment\" width=\"600\" height=\"150\" data-srcset=\"https:\/\/assignmenttask.com\/answers\/wp-content\/uploads\/2019\/04\/Order-Your-Assignment.jpg 600w, https:\/\/assignmenttask.com\/answers\/wp-content\/uploads\/2019\/04\/Order-Your-Assignment-300x75.jpg 300w, https:\/\/assignmenttask.com\/answers\/wp-content\/uploads\/2019\/04\/Order-Your-Assignment-360x90.jpg 360w\" data-sizes=\"(max-width: 600px) 100vw, 600px\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" style=\"--smush-placeholder-width: 600px; --smush-placeholder-aspect-ratio: 600\/150;\" \/><noscript><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1261 size-full\" title=\"Order Now\" src=\"https:\/\/assignmenttask.com\/answers\/wp-content\/uploads\/2019\/04\/Order-Your-Assignment.jpg\" alt=\"Order-Your-Assignment\" width=\"600\" height=\"150\" srcset=\"https:\/\/assignmenttask.com\/answers\/wp-content\/uploads\/2019\/04\/Order-Your-Assignment.jpg 600w, https:\/\/assignmenttask.com\/answers\/wp-content\/uploads\/2019\/04\/Order-Your-Assignment-300x75.jpg 300w, https:\/\/assignmenttask.com\/answers\/wp-content\/uploads\/2019\/04\/Order-Your-Assignment-360x90.jpg 360w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/noscript><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mean, Median and Mode &nbsp; Given a list of integers, write a program to print the mean, median and mode. Mean &#8211; The average value of all the numbers. Median &#8211; The mid-point value in the sorted list. Mode &#8211; The most common value in the list. &nbsp; If multiple elements with same frequency are present, print all the values with same frequency in increasing order. Input The input will be a single line containing space-separated integers. Output The first line of output should contain the mean, round off the value to 2 decimal places. The second line of output <a href=\"https:\/\/assignmenttask.com\/answers\/mean-median-and-mode\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[729],"tags":[],"_links":{"self":[{"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/posts\/5419"}],"collection":[{"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/comments?post=5419"}],"version-history":[{"count":5,"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/posts\/5419\/revisions"}],"predecessor-version":[{"id":5424,"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/posts\/5419\/revisions\/5424"}],"wp:attachment":[{"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/media?parent=5419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/categories?post=5419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmenttask.com\/answers\/wp-json\/wp\/v2\/tags?post=5419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}