def main(): a = int(input("enter the number")) def factorial(n): print() b =1 for i in range(1, a + 1): b = b * i print(b) c = input("want to find for onother number=") if c == "y" or c == "yes": main() factorial(a) main()
Just did a few little tweakings to your code with a for loop and didn't use ".format" at the end to show the output x = int(input("enter a number")) z=1 for i in range(1,x+1): z*=i print("factorial of", x, "is",z) Hope you would like this as well. One more thing use *= instead of z=z*x.
factorial in my way sir! def facto(num): e = 1 for i in range(1,num+1): e *= i print("factorial of ",num,'! is ',e) user = int(input("Enter which number factorial you want : ")) facto(5)
def fact(n): if n < 0: print('Should be +ve number') else: a = 1 for i in range (1, n + 1): a = a * i return a x = int(input('give a number for factorial = ')) result = fact(x) print('the factorial of ', x, 'is = ', result)
Another awesome video! I also watched the one that accomplishes this by recursion. Howeverm in this particular video, I would suggest to include the conditions to take care of negative integers, 0 and 1 as the argument values.
def factorial(): j = 1 valid = False while not valid: try: x = int(input("Enter value to find factorial for: ")) valid = True if x < 0: print("Factorial is a quantity only defined for all integers greater than or equal to 0") factorial() except ValueError: print("Invalid input, please use an integer.") for i in range(1, x+1): j = j*i print (j) factorial()
Hi, I tried this way before watching your video. i'm new to Python. ## print value of 5! 5*4*3*2*1 from array import * n= int(input("enter value to generate factorial value: ")) arr = array('i',[]) fact= 0 result = 1 i=0 j=0 for i in range(n): arr.append(i+1)
while j < len(arr): result = result* arr[j] j+=1 print(result)
def factorial(number): counter = 1 result = 1 while number > counter: counter+=1 result = result*counter return result print(factorial(int(input("Please enter the number: "))))
alien one is better than the experimental 'welcome theme' you used in the previous video. 'Welcome back aliens' fills our heart with happiness and a desire to do something great.
in 2nd case the f value "1"remains only naa , f = f * i = 1*1=1 f stores 1 only naa then f= f*i = 1*2 = 2 i= 2, f=1 next, f stores 2, f= f*i= 2*2=4 f stores 4 then, f= f*i= 6*4=24 4! = 24
ef fact(n): x = n r = 1 while x >= 1: r*=x x-=1 print('the result is {}'.format(r)) f = int(input('please input the value of your nummber to accont the factorial')) fact(f)
# if you want to print this pattern: "5 = 5 x 4 x 3 x 2 x 1" def fac(n): f = 1 for i in range(1, n + 1): f = f * i for j in range(n, 0, -1): if j != 1: print(j, "x ", end="") else: print(j, end="") print(" =", f) data = int(input("Enter the number: ")) fac(data)
def fact(f): if f>=0: n=1 for i in range(f): n=(f-i)*n print(n) else: print("Enter a positive number") f=int(input("Enter the number for which to find factorial: ")) print("The factorial of the number is: ") fact(f)
from math import * x = int(input("Factorial of this number")) k = factorial(x) print("the factorial of {} is {}".format(x, k)) def fattoriale(n): p = n if n == 0: return 1 else: for i in range(1, n): p *= i return p print("the factorial of {} is {}".format(x, fattoriale(x)))
tried like this def fact(n): result=1 while n>=1: result*=n n-=1 return result a= int(input("enter a positive number: ")) result= fact(a) print("factorial of given number is: ", result)
I'm little bit miserable sir bcz I did some errors in coding anything errors means coding right so no problem I practice more examples tq sir for giving such a life platform......👌👌🙏🙏
x=0 n=int(input("Enter the number whose fact you want to find")) for i in range(n,1,-1): if(i==n): x=n else: n=n*i print("Factorial is...") print(n) quit() Tried something different....
Alternative Code:::: def fact(n): x=1 if n==0: return 1 else: for i in range(n): x=x*(i+1) return x print("Enter the number to calculate factorial: ",end=" ") n=int(input()) value= fact(n) print("The value is:", value)
insted of telusko learnings it should be telusko blessings
def main():
a = int(input("enter the number"))
def factorial(n):
print()
b =1
for i in range(1, a + 1):
b = b * i
print(b)
c = input("want to find for onother number=")
if c == "y" or c == "yes":
main()
factorial(a)
main()
This programming example is well thought out and kinda refreshing! It helps me to get back to tutorial again!. thanks for your selfless act.
No one can beat you in teaching python thanku ❤️
Maybe i can
@@hellobro495 bro im from non coding background .past one week im lerning python.but still i cant write a single code. can you teach me
factorial without functions::
x = int(input("enter a number"))
z=1
while x>0:
z=z*x
x=x-1
print("factorial of x is",z)
n=int(input("enter the range"))
N1=1
For I in range(1, n+1)
N1=N1*i
Print(N1)
I think it's the easiest process
Just did a few little tweakings to your code with a for loop and didn't use ".format" at the end to show the output
x = int(input("enter a number"))
z=1
for i in range(1,x+1):
z*=i
print("factorial of", x, "is",z)
Hope you would like this as well. One more thing use *= instead of z=z*x.
I feel sorry for the first time on youtube about forget to like videos. Thank youuuuu!!!!
factorial in my way sir!
def facto(num):
e = 1
for i in range(1,num+1):
e *= i
print("factorial of ",num,'! is ',e)
user = int(input("Enter which number factorial you want : "))
facto(5)
n=int(input("enter any no"))
def fact(n):
for i in range(1,n):
n=n*i
print(n,end=" ")
fact(n)
output
enter any no 5
5 10 30 120
you got great acting skills n also you have an amazing future in cinema man
why like that
k = int(input("Enter the number to calculate the factoroial "))
j = 1
for i in range(1,k+1):
j = i * j
print ("The factorial of " ,k, "is", j)
Great buddy!!!
Great buddy!!!
What If user inputs 0 as the value 🤨
def fac(n):
if n==0:
return 1
s=1
for i in range(1,n+1):
s=s*i
return s
n=int(input("Enter a no."))
ans=fac(n)
print("Factorial = ",ans)
factorial of a number
def fact(n):
x=n
for i in range(1,n):
x*=(n-i)
return x
result=fact(5)
print(result)
def fib(n, s=1):
a = 0
b = 1
if n
z = int(input('enter the number which you waant to find the factorial of it: '))
c = 1
d = 2
for a in range(z-1):
b = c * d
c = b
d +=1
if z
pls explain the logic
def fact(n):
if n < 0:
print('Should be +ve number')
else:
a = 1
for i in range (1, n + 1):
a = a * i
return a
x = int(input('give a number for factorial = '))
result = fact(x)
print('the factorial of ', x, 'is = ', result)
Sir i a getting errorwhile executing this code
Easiest Answer
x = int(input("Enter a Number: "))
result = 1
for i in range(x):
result = result * (x - i)
print(result)
GJ Jonty, you put these frauds to shame
Telusko you are a blessing.
Another awesome video! I also watched the one that accomplishes this by recursion. Howeverm in this particular video, I would suggest to include the conditions to take care of negative integers, 0 and 1 as the argument values.
def factorial():
j = 1
valid = False
while not valid:
try:
x = int(input("Enter value to find factorial for: "))
valid = True
if x < 0:
print("Factorial is a quantity only defined for all integers greater than or equal to 0")
factorial()
except ValueError:
print("Invalid input, please use an integer.")
for i in range(1, x+1):
j = j*i
print (j)
factorial()
I made a shorter code
def fact (x):
F = 1
For i in range ( 1, x+1):
f = f * i
Print (f)
fact(5)
You say 'into', I say 'times'. Enjoying the series. Thanks.
Hi, I tried this way before watching your video. i'm new to Python.
## print value of 5! 5*4*3*2*1
from array import *
n= int(input("enter value to generate factorial value: "))
arr = array('i',[])
fact= 0
result = 1
i=0
j=0
for i in range(n):
arr.append(i+1)
while j < len(arr):
result = result* arr[j]
j+=1
print(result)
b=1
for i in range(5):
a=i+1
c=a*b
b=c
print(c)
factorial using while loop
def fac(n):
f=1
i=1
while(i
def factorial(number):
counter = 1
result = 1
while number > counter:
counter+=1
result = result*counter
return result
print(factorial(int(input("Please enter the number: "))))
2nd assignment answer
def fib(n):
if(n
This is how I do it:
import math
n = int(input("Enter a number: "))
print("Factorial of", n, "is ", math.factorial(n)".")
Another way:
def func(x):
if x==1:
return 1
else:
return x * func(x-1)
print(func(5))
n=int(input("enter the range"))
N1=1
For I in range(1, n+1)
N1=N1*i
Print(N1)
I think it's the easiest process
Best Explanation and Teaching Method. Simply Awesome!!
n=int(input("enter the no. :"))
res=1
while n>0:
res*=n
n-=1
print(res)
The factorial of 0 is also 1 which means we have to use if statement too
Yes
If n==0:
Print(f)
def fact(n):
f=1
for i in range(1,n+1):
f=f*i
print(f)
n=int(input("Enter the number you want"))
fact(n)
def fact(n):
total = 1
for i in range(1, n+1):
total *= i
print('Current Number is :', i, 'Total is = ', total)
fact(5)
QUESTION 2
def fib(n):
lst=[]
k=0
l=1
x=0
lst.append(k)
lst.append(l)
while xn:
break
lst.append(x)
k=l
l=x
print(lst)
n=int(input("enter the maximum limit"))
fib(n)
def fac(n):
a=[ ]
for i in range(1,n+1):
a.append(i)
import numpy
c=numpy.prod(a)
Print (c)
def fact(n):
res=1
for i in range(n,1,-1): # in reverse order
res*=i
return res
n=int(input("enter the range : "))
res=fact(n)
print(res)
j=1
def factorial(n):
global j
for i in range(1,n+1):
f = i * j
j=f
print(f)
factorial(5)
In case of recursion:
x = int(input())
def factorial(n):
if n
Rytt
def fact(n):
x=n
for i in range(1,n):
n=n+(x-i)
print(n)
n=int(input("enter the number"))
fact(n)
Alternative Code using while loop
num =int(input("Enter the number:"))
factorial = 1
while num>1:
factorial =factorial*num
num =num-1
print(factorial)
I think in place of 1
We replace 0 is the best choice.
In condition
factorial
def fact(n):
a=1
x=1
for i in range (n):
x=x*a
a+=1
print(x)
fact(10)
def factorial(no):
fact = 1
for i in range(no):
fact = fact * (i + 1)
return fact
no = 3
result = factorial(no)
print(result)
Step by step pure technical description.
buy adding if c
see
def factorial(n):
s=1
while n>0:
s*=n
n-=1
print(s)
def fact(n):
y=1
for i in range(1,n+1):
y=y*i
print(y)
fact(5)
def multiply (n):
if n
alien one is better than the experimental 'welcome theme' you used in the previous video. 'Welcome back aliens' fills our heart with happiness and a desire to do something great.
in 2nd case the f value "1"remains only naa , f = f * i = 1*1=1
f stores 1 only naa then
f= f*i = 1*2 = 2
i= 2, f=1 next,
f stores 2,
f= f*i= 2*2=4
f stores 4 then,
f= f*i= 6*4=24 4! = 24
ef fact(n):
x = n
r = 1
while x >= 1:
r*=x
x-=1
print('the result is {}'.format(r))
f = int(input('please input the value of your nummber to accont the factorial'))
fact(f)
n=int(input("Enter a number"))
def fact(n):
abtakkaprod=1
for i in range(1,n+1):
abtakkaprod=abtakkaprod*i
print("Factorial=",abtakkaprod)
fact(n)
Why do I get 1 after performing as below?
def fact(n):
f=1
for i in range(1,n+1):
f=f*1
return f
x = 4
result = fact(x)
print(result)
my code for finding factorial->
a=int(input("enter the number:"))
def fac(a):
b = 1
for i in range(1,a+1):
b=b*i
print(b)
fac(a)
sir,how can we move step by step while using debug option
def fac(n):
if n==1 or n==0:
return 1
else:
return n*fac(n-1)
print("{}! = {}".format(5,fac(5)))
def factorial(n):
for i in range(n,2,-1):
a =i-1
n= n*a
return n
print(factorial(5))
Simple Way:
fact = int(input("enter the number "))
num = 1;
for i in range(1, fact+1):
num = num * i;
print(num)
def fib(n):
if n < 0:
print("Must be a number above zero! ")
a = 0
b = 1
if n == 1:
print(a)
elif n > 1:
print(a)
print(b)
for i in range(2,n):
c = a + b
a = b
b = c
print(c)
fib(-2)
def fact(num):
a=1;
for i in range(1,num+1):
a=a*i
return a
num=int(input("enter the number"))
a=fact(num)
print(a)
def fib(n):
a = 0
b = 1
if n 100:
print('This function\'s result set can only handle fibonacci numbers up to {}'.format(c))
break;
you can also do :
def factorial(n):
if n == 0:
return 1
else:
recurse = factorial(n-1)
result = n * recurse
return result
# if you want to print this pattern: "5 = 5 x 4 x 3 x 2 x 1"
def fac(n):
f = 1
for i in range(1, n + 1):
f = f * i
for j in range(n, 0, -1):
if j != 1:
print(j, "x ", end="")
else:
print(j, end="")
print(" =", f)
data = int(input("Enter the number: "))
fac(data)
could u pls explain this
def fact(f):
if f>=0:
n=1
for i in range(f):
n=(f-i)*n
print(n)
else:
print("Enter a positive number")
f=int(input("Enter the number for which to find factorial: "))
print("The factorial of the number is: ")
fact(f)
number = int(input("Enter the Number"))
factorial = 1
if number
def fact(n):
f=1
while n!=1:
f=f*n
n-=1
return f
n=int(input("enter the last value"))
result=fact(n)
print(result)
def fact(num):
x = num-1
for i in range(1,num):
num *= x
x -= 1
return num
print(fact(4))
def fac(n):
for i in range(1,n):
n=i*n
print(n)
fac(4)
Thank you very much Sir. After watching your videos I have not any confusion
Factorial :
i = 1
first = 1
second = 1
user_value = int(input("please enter value"))
while i
really you explain very organised manner sir .plz make videos on advanced python
from math import *
x = int(input("Factorial of this number"))
k = factorial(x)
print("the factorial of {} is {}".format(x, k))
def fattoriale(n):
p = n
if n == 0:
return 1
else:
for i in range(1, n):
p *= i
return p
print("the factorial of {} is {}".format(x, fattoriale(x)))
Very good video sir Thanks
def factorial(a):
for i in range(1,a):
a = a*i
print(a)
factorial(10)
this works as same for me:
n = int(input('Enter the number: '))
x = n
for i in range(1, n):
n = i*n
print(x, 'factorial is :', n)
factorial without loop:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
tried like this
def fact(n):
result=1
while n>=1:
result*=n
n-=1
return result
a= int(input("enter a positive number: "))
result= fact(a)
print("factorial of given number is: ", result)
n=int(input("enter "))
k=1
for i in range(n):
k=k*n
n-=1
print(k)
The Best Teacher Award Goes To Sir Navin
Thank you very much. You are a genius.
Where are you man?? The brain of computer aren't you??
def tino(n):
f=1
for i in 5,2,3,4:
f=f*i
return f
x=5
result=tino(x)
print(result)
Y this code is giving an output value of 5 ?
best explanation .... God bless you ....
AGH almost half way through this playlist!
n,p = int(input("Enter any number :")),1
for i in range(1,n+1):
p *= i
print("{}! = {}".format(n,p))
def fact(x):
f=1
for i in range(1,x+1):
f=f*i
return f
result = fact(5)
print(result)
I'm little bit miserable sir bcz I did some errors in coding anything errors means coding right so no problem I practice more examples tq sir for giving such a life platform......👌👌🙏🙏
n=int(input('enter the number'))
def fact(n):
l=1
for i in range(1,n+1):
l=l*i
return l
result=fact(n)
print(result)
By this we can't find 0! It will give 0 but real ans is one
For this u need to add one base condition as such other languages
def fact(n):
x=1
for i in range(1,n+1):
#x = i*(i+1)
x=x*i
print(x)
v_from_user = int(input("Enter an integer number: "))
fact(v_from_user)
# Solved
amazing videos.. thank you sir
x=0
n=int(input("Enter the number whose fact you want to find"))
for i in range(n,1,-1):
if(i==n):
x=n
else:
n=n*i
print("Factorial is...")
print(n)
quit()
Tried something different....
Alternative Code::::
def fact(n):
x=1
if n==0:
return 1
else:
for i in range(n):
x=x*(i+1)
return x
print("Enter the number to calculate factorial: ",end=" ")
n=int(input())
value= fact(n)
print("The value is:", value)
Not gud
Thanks for explaining this.
Sir ur teaching is awesome but little bit decrease the speed of teaching
Man, best python series.
Awesome 👍
U r an amazing person ... i like the way u say B-Bye😊.... May God Always bless u for ur effort ur bringing in students life 🙏😇
# recursion
def factorial(x):
if x==0:
return
else:
n = x*factorial(x-1)
return(n)
x = int(input("Enter a Number"))
f = factorial(x)
print(f)
Alternative code: easy to understand:
def fact(n):
f=1
for i in range(1, n+1):
f=f*i
print(f)
fact(int(input('Enter the value to find factorial: ')))