Skip to content

Commit 658d0ca

Browse files
Merge branch 'geekcomputers:master' into master
2 parents 483b4ba + cbc6235 commit 658d0ca

17 files changed

+204
-78
lines changed

Add two numbers.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

Addtion of two numbers.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
numpy==1.25.2
2-
opencv_python==4.8.0.74
3-
mediapipe==0.10.2
2+
opencv_python==4.8.1.78
3+
mediapipe==0.10.5

PDF/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Pillow==10.0.0
1+
Pillow==10.0.1
22
fpdf==1.7.2

Sum of digits of a number.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
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
7-
print("Sum of digits is: "+str(q))
1+
# Python code to calculate the sum of digits of a number, by taking number input from user.
2+
3+
import sys
4+
5+
def get_integer():
6+
for i in range(3,0,-1): # executes the loop 3 times. Giving 3 chances to the user.
7+
num = input("enter a number:")
8+
if num.isnumeric(): # checks if entered input is an integer string or not.
9+
num = int(num) # converting integer string to integer. And returns it to where function is called.
10+
return num
11+
else:
12+
print("enter integer only")
13+
print(f'{i-1} chances are left' if (i-1)>1 else f'{i-1} chance is left') # prints if user entered wrong input and chances left.
14+
continue
15+
16+
17+
def addition(num):
18+
Sum=0
19+
if type(num) is type(None): # Checks if number type is none or not. If type is none program exits.
20+
print("Try again!")
21+
sys.exit()
22+
while num > 0: # Addition- adding the digits in the number.
23+
digit = int(num % 10)
24+
Sum += digit
25+
num /= 10
26+
return Sum # Returns sum to where the function is called.
27+
28+
29+
30+
if __name__ == '__main__': # this is used to overcome the problems while importing this file.
31+
number = get_integer()
32+
Sum = addition(number)
33+
print(f'Sum of digits of {number} is {Sum}') # Prints the sum

add 2 number.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

add 2 numbers.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

add two no.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

add two number.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)