{"id":125,"date":"2025-03-13T07:10:28","date_gmt":"2025-03-13T07:10:28","guid":{"rendered":"https:\/\/alpeshconnect.in\/blog\/?p=125"},"modified":"2025-03-13T07:10:28","modified_gmt":"2025-03-13T07:10:28","slug":"python-list-example-with-input-ve-ve-numbers","status":"publish","type":"post","link":"https:\/\/alpeshconnect.in\/blog\/2025\/03\/13\/python-list-example-with-input-ve-ve-numbers\/","title":{"rendered":"Python List example with input +ve \/ -ve numbers."},"content":{"rendered":"\n<p>WAP in Python to read list of N integers ( positive as well as negative ) Create two new lists, one having all positive numbers and the other having all negative numbers from the given list. Print all three lists separately.<\/p>\n\n\n\n<p><strong>Solution :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Input: Read list of integers from the user\nN = int(input(\"Enter the number of integers: \"))\nnumbers = &#91;]\n\n# Collecting all integers from the user\nfor i in range(N):\n    num = int(input())\n    numbers.append(num)\n\n# Initialize two empty lists for positive and negative numbers\npositive_numbers = &#91;]\nnegative_numbers = &#91;]\n\n# Segregate the numbers into positive and negative lists\nfor num in numbers:\n    if num >= 0:\n        positive_numbers.append(num)\n    else:\n        negative_numbers.append(num)\n\n# Print the lists\nprint(\"Original List:\", numbers)\nprint(\"Positive Numbers List:\", positive_numbers)\nprint(\"Negative Numbers List:\", negative_numbers)\n<\/code><\/pre>\n\n\n\n<p><strong>Solution 2 :<\/strong> <strong>Using<\/strong> <strong>list comprehension<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Input: Read list of integers from the user\nN = int(input(\"Enter the number of integers: \"))\nnumbers = &#91;int(input()) for i in range(N)]  # List comprehension to get input\n\n# Segregate positive and negative numbers\npositive_numbers = &#91;num for num in numbers if num >= 0]\nnegative_numbers = &#91;num for num in numbers if num &lt; 0]\n\n# Print all three lists\nprint(\"Original List:\", numbers)\nprint(\"Positive Numbers List:\", positive_numbers)\nprint(\"Negative Numbers List:\", negative_numbers)\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WAP in Python to read list of N integers ( positive as well as negative ) Create two new lists, one having all positive numbers and the other having all negative numbers from the given list. Print all three lists separately. Solution : Solution 2 : Using list comprehension<\/p>\n","protected":false},"author":1,"featured_media":96,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,44],"tags":[25,26,46,45],"class_list":["post-125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bca","category-programming-skills","tag-bca","tag-bca-paper-solution","tag-programming-skills","tag-python"],"_links":{"self":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":1,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":126,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/125\/revisions\/126"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media\/96"}],"wp:attachment":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}