Skip to content

Commit 561d72b

Browse files
committed
sequence update
1 parent d3814de commit 561d72b

16 files changed

+127
-39
lines changed

Diff for: Mathematics/2.1.1.count_digits_iterative.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
COUNT DIGITS METHOD - I: Iterative Method
3+
4+
Given a number count the number of digits
5+
6+
IP: 65415
7+
OP: 5
8+
9+
IP: 787878
10+
OP: 6
11+
12+
TC: O(log10(n))
13+
SC: O(1)
14+
"""
15+
16+
def count_digit(num: int)-> int:
17+
""" Iterative Method
18+
19+
Args:
20+
num (int): number to count digits of
21+
22+
Returns:
23+
int: Number of digits in a number
24+
"""
25+
count = 0
26+
while num != 0:
27+
num //= 10
28+
count += 1
29+
return count
30+
31+
if __name__ == '__main__':
32+
N = int(input('Enter the number: '))
33+
print("The number of digits in ", N, "is", count_digit(N))

Diff for: Mathematics/2.1.2.count_digits_recursive.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
COUNT DIGITS METHOD - II: Recursive Method
3+
4+
Given a number count the number of digits
5+
6+
IP: 65415
7+
OP: 5
8+
9+
IP: 787878
10+
OP: 6
11+
12+
TC: O(log n)
13+
SC: O(log n)
14+
"""
15+
16+
def count_digit(num: int)-> int:
17+
""" Recursive Method
18+
19+
Args:
20+
num (int): number to count digits of
21+
22+
Returns:
23+
int: Number of digits in a number
24+
"""
25+
if num == 0:
26+
return 0
27+
return 1 + count_digit(num//10)
28+
29+
30+
if __name__ == '__main__':
31+
N = int(input('Enter the number: '))
32+
print("The number of digits in ", N, "is", count_digit(N))

Diff for: Mathematics/2.1.3.count_digit_conversion.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
COUNT DIGITS METHOD - I: Iterative Method
3+
4+
Given a number count the number of digits
5+
6+
IP: 65415
7+
OP: 5
8+
9+
IP: 787878
10+
OP: 6
11+
12+
13+
"""
14+
15+
def count_digit(n):
16+
""" Conversion """
17+
# n = len(str(n))
18+
# return n
19+
20+
n = 23965465
21+
print("The number of digits in ", n, "is", count_digit(n))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: Mathematics/2.6.1.check_for_prime.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
CHECK FOR PRIME
3+
4+
Check whether the given number is Prime or not.
5+
6+
IP: N = 5
7+
OP: The number 5 is Prime.
8+
9+
IP: N = 10
10+
OP: The number 10 is not Prime.
11+
12+
TC: O(sqrt(n))
13+
SC: O(1)
14+
"""
15+
16+
from math import sqrt
17+
18+
def check_prime(num: int) -> bool:
19+
"""Check if the number is prime
20+
21+
Args:
22+
num (int): number to check
23+
24+
Returns:
25+
bool: True if number is Prime, False otherwise
26+
"""
27+
# Base Case
28+
if num <= 1:
29+
return False
30+
# Verifying from 2 to sqrt(num)
31+
for i in range(2, int(sqrt(num)) + 1):
32+
if num % i == 0:
33+
return False
34+
return True
35+
36+
if __name__ == '__main__':
37+
n = int(input("Enter a number to check prime..."))
38+
if check_prime(n):
39+
print(f'The number {n} is Prime.')
40+
else:
41+
print(f'The number {n} is not Prime.')
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: Mathematics/check_for_prime.py

-22
This file was deleted.

Diff for: Mathematics/count_digits.py

-17
This file was deleted.

0 commit comments

Comments
 (0)