{"id":749,"date":"2021-10-27T12:00:40","date_gmt":"2021-10-27T12:00:40","guid":{"rendered":"https:\/\/ethosspace.com\/programmers\/?p=749"},"modified":"2021-10-27T12:13:27","modified_gmt":"2021-10-27T12:13:27","slug":"cube-of-numbers-in-python-using-while-for-loop-user-input","status":"publish","type":"post","link":"https:\/\/ethosspace.com\/programmers\/cube-of-numbers-in-python-using-while-for-loop-user-input\/","title":{"rendered":"calculate cube of numbers in python using while, for loop"},"content":{"rendered":"\n<p>Here is simple three line program to calculate cube and print it as per user input or range using while loop<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>#Program to find cube of numbers\n#taking input from user till how many numbers user want to print cube\nrangeNo=int(input(&quot;enter upto which number you want to print cube\\t&quot;))\n\ni = 1;\nwhile i &lt;= rangeNo:\n    cubeNo = 0\n    cubeNo = i * i * i\n    print(&quot;cube of %d is ===&gt;   %f&quot;  %(i,cubeNo))\n    i=i+1<\/code><\/pre><\/div>\n\n\n\n<p>Output<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>enter upto which number you want to print cube\t5\ncube of 1 is ===&gt;   1.000000\ncube of 2 is ===&gt;   8.000000\ncube of 3 is ===&gt;   27.000000\ncube of 4 is ===&gt;   64.000000\ncube of 5 is ===&gt;   125.000000<\/code><\/pre><\/div>\n\n\n\n<p>Below program is to calculate cube of numbers using for loop up to number (user input)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>#Program to find cube of numbers\n#taking input from user till how many numbers user want to print cube\nrangeNo=int(input(&quot;enter upto which number you want to print cube\\t&quot;))\n\nj = 1;\nfor i in range(j,rangeNo+1):\n    cubeNo = 0\n    cubeNo = i * i * i\n    print(&quot;cube of %d is ===&gt;   %f&quot;  %(i,cubeNo))<\/code><\/pre><\/div>\n\n\n\n<p>Output<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>enter upto which number you want to print cube\t5\ncube of 1 is ===&gt;   1.000000\ncube of 2 is ===&gt;   8.000000\ncube of 3 is ===&gt;   27.000000\ncube of 4 is ===&gt;   64.000000\ncube of 5 is ===&gt;   125.000000<\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is simple three line program to calculate cube and print it as per user input or range using while loop Output Below program is to calculate cube of numbers using for loop up to number (user input) Output<\/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-749","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":"Here is simple three line program to calculate cube and print it as per user input or range using while loop Output Below program is to calculate cube of numbers using for loop up to number (user input) Output","_links":{"self":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/749","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=749"}],"version-history":[{"count":4,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/749\/revisions"}],"predecessor-version":[{"id":755,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/749\/revisions\/755"}],"wp:attachment":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/media?parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/categories?post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/tags?post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}