Skip to content

Commit 90533ae

Browse files
Merge branch 'geekcomputers:master' into testing
2 parents 02af73d + 9cb0144 commit 90533ae

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

FIND FACTORIAL OF A NUMBER.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Python program to find the factorial of a number provided by the user.
22

33
def factorial(n):
4-
if n < 0:
4+
if n < 0: # factorial of number less than 0 is not possible
55
return "Oops!Factorial Not Possible"
6-
elif n == 0:
6+
elif n == 0: # 0! = 1; when n=0 it returns 1 to the function which is calling it previously.
77
return 1
88
else:
9-
return n*factorial(n-1)
9+
return n*factorial(n-1)
10+
#Recursive function. At every iteration "n" is getting reduced by 1 until the "n" is equal to 0.
1011

11-
n = int(input())
12-
print(factorial(n))
12+
n = int(input("Enter a number: ")) # asks the user for input
13+
print(factorial(n)) # function call
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
numpy==1.25.2
2-
opencv_python==4.8.0.74
2+
opencv_python==4.8.0.76
33
mediapipe==0.10.3

Sum of digits of a number.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
q=0
2-
n=int(input("Enter Number: "))
3-
while(n>0):
4-
r=n%10
5-
q=q+r
6-
n=n//10
1+
q=0 # Initially we assigned 0 to "q", to use this variable for the summation purpose below.
2+
# The "q" value should be declared before using it(mandatory). And this value can be changed later.
3+
4+
n=int(input("Enter Number: ")) # asking user for input
5+
while n>0: # Until "n" is greater than 0, execute the loop. This means that until all the digits of "n" got extracted.
6+
7+
r=n%10 # Here, we are extracting each digit from "n" starting from one's place to ten's and hundred's... so on.
8+
9+
q=q+r # Each extracted number is being added to "q".
10+
11+
n=n//10 # "n" value is being changed in every iteration. Dividing with 10 gives exact digits in that number, reducing one digit in every iteration from one's place.
12+
713
print("Sum of digits is: "+str(q))

0 commit comments

Comments
 (0)