program to print the factorial of a number within a range in python
Answers
Answer:
See this example:
num = int(input("Enter a number: "))
factorial = 1.
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
How do you print the range of a number in Python?
Convert range() to List. If you execute print( type( range(10) ) ) you will get <class 'range'> as output. Python range() function doesn't return a list type. It returns a range object, i.e., sequence object of type range, So as a result, we get an immutable sequence object of integers.
How do you find the factorial of a number using a while loop in Python?
Using While Loop
num = int(input("enter a number: "))
fac = 1.
i = 1.
while i <= num:
fac = fac * i.
i = i + 1.
print("factorial of ", num, " is ", fac)
Explanation:
Hope you have satisfied with this answer. So please follow me and thank me and make me as brainlesset soon and vote my answer.
for is the keyword in python which is used to form a loop whose definite length is known , it does not takes the last value . For example , the above loop will run till the number 'n' entered by the user and not till 'n+1' .
print is the keyword in python programming language . It print anything which is written within it .
input takes the input from the user in the form of string .
int converts the input into integer form .