Page 1 of 1

Given below is a program that calculates the factorial of a number. Rearrange the lines of code below such that this fun

Posted: Mon Jun 06, 2022 5:48 pm
by answerhappygod
Given Below Is A Program That Calculates The Factorial Of A Number Rearrange The Lines Of Code Below Such That This Fun 1
Given Below Is A Program That Calculates The Factorial Of A Number Rearrange The Lines Of Code Below Such That This Fun 1 (78.85 KiB) Viewed 32 times
Given below is a program that calculates the factorial of a number. Rearrange the lines of code below such that this function returns the correct output as shown below. For example, if the input parameter num is 3, your function should return the factorial of 3, which is 6 (because 1 * 2*3= 6). If the input parameter num is -3, your function should return the string "Invalid input". This is because the input is a negative number. Note that you should make sure the indentation is correct! Drag from here Drop blocks here return 'Invalid input' return fact def factorial(n): fact = 1 fact *= i if n < 0: for i in range (1, n+1):