{"id":395,"date":"2021-10-18T10:49:36","date_gmt":"2021-10-18T10:49:36","guid":{"rendered":"https:\/\/ethosspace.com\/programmers\/?p=395"},"modified":"2021-11-02T15:34:38","modified_gmt":"2021-11-02T15:34:38","slug":"python-program-to-find-largest-smallest-among-n-numbers","status":"publish","type":"post","link":"https:\/\/ethosspace.com\/programmers\/python-program-to-find-largest-smallest-among-n-numbers\/","title":{"rendered":"Python Program to Find Largest &#038; Smallest among N Numbers"},"content":{"rendered":"\n<p> In Python there are many ways to identify largest or smallest number from user input. Here we are using for loop.  <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>nrange = int(input(&quot;\\n\\t From how many numbers you want to find smallest & largest number\\t&quot;))\nnum = int(input(&quot;\\n\\t Enter number 1 ==&gt;\\t&quot;))\nmin_num = num\nmax_num = num\nfor x in range(nrange-1):\n \n    num=int(input(&#39;\\n\\t Enter number %d ==&gt;\\t&#39;%(x+2)))\n    if ( num &lt; min_num ):\n        min_num = num\n    if ( num &gt; max_num ):\n        max_num = num\n\nprint(&#39;\\n\\t Maximum number is %d&#39;%(max_num))\nprint(&#39;\\n\\t Minimum number is %d&#39;%(min_num))<\/code><\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\t From how many numbers you want to find smallest &amp; largest number\t3\n3\n\n\t Enter number 1 ==&gt;\t3\n\n\t Enter number 2 ==&gt;\t3\n\n\t Enter number 3 ==&gt;\t4\n\n\t Maximum number is 4\n\n\t Minimum number is 3\n&gt;&gt;&gt; <\/code><\/pre>\n\n\n\n<p>In above program we are accepting first number from user and declaring it as maximum and minimum number.<\/p>\n\n\n\n<p>Further in for loop we are accepting numbers from user and comparing it with variables maximum and minimum to interchange.<\/p>\n\n\n\n<p>Recommended to write logic on paper and execute it manually then use editor.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Python there are many ways to identify largest or smallest number from user input. Here we are using for loop. Output In above program we are accepting first number from user and declaring it as maximum and minimum number. Further in for loop we are accepting numbers from user and comparing it with variables [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[11],"tags":[],"class_list":["post-395","post","type-post","status-publish","format-standard","hentry","category-running-code-and-program"],"aioseo_notices":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"sparkling-featured":false,"sparkling-featured-fullwidth":false,"tab-small":false},"uagb_author_info":{"display_name":"program45_-rt8nb","author_link":"https:\/\/ethosspace.com\/programmers\/author\/program45_-rt8nb\/"},"uagb_comment_info":0,"uagb_excerpt":"In Python there are many ways to identify largest or smallest number from user input. Here we are using for loop. Output In above program we are accepting first number from user and declaring it as maximum and minimum number. Further in for loop we are accepting numbers from user and comparing it with variables&hellip;","_links":{"self":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/comments?post=395"}],"version-history":[{"count":11,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/395\/revisions"}],"predecessor-version":[{"id":826,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/395\/revisions\/826"}],"wp:attachment":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/media?parent=395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/categories?post=395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/tags?post=395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}