{"id":832,"date":"2021-05-12T19:58:45","date_gmt":"2021-05-12T14:28:45","guid":{"rendered":"https:\/\/cbsepython.in\/?p=832"},"modified":"2021-05-12T19:58:45","modified_gmt":"2021-05-12T14:28:45","slug":"while-loop-exercises-for-cbse-computer-science","status":"publish","type":"post","link":"https:\/\/cbsepython.in\/while-loop-exercises-for-cbse-computer-science\/","title":{"rendered":"Python while loop exercises for CBSE Computer Science"},"content":{"rendered":"<h2>Python while loop exercises for CBSE Computer Science<\/h2>\n<p>&nbsp;<\/p>\n<h3>1- Python program to print First 10 Even numbers using while loop<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">num = 2\r\nwhile(num&lt;=20):\r\n    print(num)\r\n    num = num + 2\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Output:<\/p>\n<pre>2\r\n4\r\n6\r\n8\r\n10\r\n12\r\n14\r\n16\r\n18\r\n20<\/pre>\n<p>&nbsp;<\/p>\n<h3>2- Python program to print First 10 Odd numbers using while loop<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">num = 1\r\nwhile(num&lt;=20):\r\n    print(num)\r\n    num = num + 2\r\n<\/pre>\n<p>Output:<\/p>\n<pre>1\r\n3\r\n5\r\n7\r\n9\r\n11\r\n13\r\n15\r\n17\r\n19<\/pre>\n<p>&nbsp;<\/p>\n<h3>3- Python program to print First 10 Natural numbers using while loop<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">num = 1\r\nwhile(num&lt;=10):\r\n    print(num)\r\n    num = num + 1\r\n<\/pre>\n<p>Output:<\/p>\n<pre>1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10<\/pre>\n<p>&nbsp;<\/p>\n<h3>4- Python program to print First 10 Whole numbers using while loop<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">num = 0\r\nwhile(num&lt;10):\r\n    print(num)\r\n    num = num + 1\r\n<\/pre>\n<div id=\"links1-content-4749\" class=\"sh-content links1-content sh-show\"><\/div>\n<div>Output:<\/div>\n<pre>0\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9<\/pre>\n<div><\/div>\n<h3>5-Python program to print first 5 numbers and their cubes using while loop.<\/h3>\n<div><\/div>\n<div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">num = 1\r\nprint(\"Numbers\\t Cube\")\r\nwhile(num&lt;=5):\r\n   print(num,\"\\t\", num ** 3)\r\n   num = num + 1\r\n<\/pre>\n<p>Output:<\/p>\n<pre>Numbers Cube\r\n1         1\r\n2         8\r\n3         27\r\n4         64\r\n5         125<\/pre>\n<\/div>\n<div><\/div>\n<div><\/div>\n<h3>6- Python program to print a series of (10, 20, 30, 40, 50) using while loop.<\/h3>\n<div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">num = 10\r\nwhile (num &lt;= 50) :\r\n    print(num, end = \" , \\n\")\r\n    num = num +10\r\n<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<div>Output:<\/div>\n<div><\/div>\n<pre>10 , 20 , 30 , 40 , 50 , \r\n\r\n\r\n<\/pre>\n<h3>7- Python program to print sum of first 10 Natural numbers using while loop.<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">num = 10\r\nsum = 0\r\nwhile num &gt;= 1:\r\n   sum = sum + num\r\n   num= num - 1\r\nprint(sum)\r\n<\/pre>\n<p>Output:<\/p>\n<pre>55<\/pre>\n<h3>8- Python program to print sum of first 10 even numbers using while loop.<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">num = 2\r\nsum = 0\r\nwhile num &lt;= 20:\r\n   sum = sum + num\r\n   num= num + 2\r\nprint(sum)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<div>Output:<\/div>\n<pre>110<\/pre>\n<h3>9- Python program to print table of a given number using while loop.<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">i = 1\r\nnum = int(input(\"Enter any number  : \"))\r\nwhile i &lt;= 10:\r\n    print(num,\" * \",i,\" = \", num * i)\r\n    i = i+1\r\n<\/pre>\n<p>Output:<\/p>\n<pre>Enter any number : 5\r\n5 * 1 = 5\r\n5 * 2 = 10\r\n5 * 3 = 15\r\n5 * 4 = 20\r\n5 * 5 = 25\r\n5 * 6 = 30\r\n5 * 7 = 35\r\n5 * 8 = 40\r\n5 * 9 = 45\r\n5 * 10 = 50<\/pre>\n<h3>10- Python program to check weather\u00a0 the inputted number is prime or not using while loop.<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">num1 = int(input(\"Enter any number : \"))\r\nk=0\r\nif num1 == 0 or num1 == 1:\r\n    print(\"Not a prime number \")\r\nelse:\r\n   i = 2\r\n   while(i&lt;num1):\r\n     if num1 % i == 0:\r\n       k = k+1\r\n     i = i+1\r\nif k == 0 :\r\n        print( num1,\"is prime number\")\r\nelse:\r\n        print(num1, \"is not prime number\")\r\n<\/pre>\n<p>Output:<\/p>\n<pre>Enter any number : 6\r\n6 is not prime number\r\n&gt;&gt;&gt;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python while loop exercises for CBSE Computer Science &nbsp; 1- Python program to print First 10 Even numbers using while loop num = 2 while(num&lt;=20): print(num) num = num + 2 &nbsp; Output: 2 4 6 8 10 12 14 16 18 20 &nbsp; 2- Python program to print First 10 Odd numbers using while [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-832","post","type-post","status-publish","format-standard","hentry","category-cbse-computer-science-with-python-class-12"],"_links":{"self":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/comments?post=832"}],"version-history":[{"count":0,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/832\/revisions"}],"wp:attachment":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/media?parent=832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/categories?post=832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/tags?post=832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}