\n
this time the program has to calculate the factorial (n!) of a non-negative number given by the user.<\/strong><\/p>\nfirst we have to understand what factorial is. it is the multiplication of all the numbers from 1 to n.<\/strong><\/p>\nn!= 1x2x3x4x5x. . . . . xn!<\/strong><\/p>\nnow we could use the python function for factorial math.factorial(n) but lets do math.<\/span><\/strong><\/p>\nfirst ask the user for a positive integer and set the folowing variables:<\/span><\/strong><\/p>\nn = int(input())<\/span><\/strong><\/p>\nf = 0 – – – – this is a counter<\/span><\/strong><\/p>\nc = 1 – – – – this will be the factorial product<\/span><\/strong><\/p>\nnow we can do this with a while or a for loop, for the while loop we could put it like this:<\/span><\/strong><\/p>\nwhile f < n:<\/span><\/strong><\/p>\n f += 1<\/span><\/strong><\/p>\n c = c*f<\/span><\/strong><\/p>\nand the for loop:<\/strong><\/span><\/span><\/p>\nfor t in n:<\/strong><\/span><\/span><\/p>\n f += 1<\/span><\/strong><\/p>\n c = c*f<\/span><\/strong><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":" this time the program has to calculate the factorial (n!) of a non-negative number given by the user.first we have to understand what factorial is. it is the multiplication of all the numbers from 1 to n.n!= 1x2x3x4x5x. . . . . xn!now we could… Continue reading →<\/span><\/a><\/p>\n","protected":false},"author":128,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3,25],"tags":[144],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/7796"}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/users\/128"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/comments?post=7796"}],"version-history":[{"count":2,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/7796\/revisions"}],"predecessor-version":[{"id":7975,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/7796\/revisions\/7975"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/media?parent=7796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/categories?post=7796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/tags?post=7796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}