0% found this document useful (0 votes)
3 views6 pages

Denil Python Program Set2

The document contains various Python programs that demonstrate how to perform mathematical checks and calculations, such as checking for prime numbers, finding Fibonacci series, determining Armstrong and perfect numbers, calculating LCM and GCD, and counting digits, vowels, and consonants in a string. Each program includes user input and iterative logic to achieve its respective task. The examples provided are straightforward and serve as basic algorithms for common mathematical problems.

Uploaded by

thenewtech1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Denil Python Program Set2

The document contains various Python programs that demonstrate how to perform mathematical checks and calculations, such as checking for prime numbers, finding Fibonacci series, determining Armstrong and perfect numbers, calculating LCM and GCD, and counting digits, vowels, and consonants in a string. Each program includes user input and iterative logic to achieve its respective task. The examples provided are straightforward and serve as basic algorithms for common mathematical problems.

Uploaded by

thenewtech1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Q: Check if a number is prime

#Program:

num = int(input("Enter a number: "))

if num > 1:

for i in range(2, num):

if num % i == 0:

print("Not a Prime Number")

break

else:

print("Prime Number")

else:

print("Not a Prime Number")

Q: Find all prime numbers in a range

#Program:

start = int(input("Start: "))

end = int(input("End: "))

for num in range(start, end + 1):

if num > 1:

for i in range(2, num):

if num % i == 0:
break

else:

print(num, end=" ")

Q: Fibonacci series up to N terms

#Program:

n = int(input("Enter number of terms: "))

a, b = 0, 1

for _ in range(n):

print(a, end=" ")

a, b = b, a + b
Q: Check Armstrong number

#Program:

num = int(input("Enter a number: "))

sum = 0

temp = num

while temp > 0:

digit = temp % 10

sum += digit ** len(str(num))

temp //= 10

print("Armstrong Number" if sum == num else "Not an Armstrong Number")

Q: List all Armstrong numbers in a range

#Program:

start = int(input("Start: "))

end = int(input("End: "))

for num in range(start, end + 1):

order = len(str(num))

sum = 0

temp = num

while temp > 0:

digit = temp % 10

sum += digit ** order


temp //= 10

if num == sum:

print(num, end=" ")

Q: Find LCM of two numbers

#Program:

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

max_num = max(a, b)

while True:

if max_num % a == 0 and max_num % b == 0:

print("LCM is", max_num)

break

max_num += 1
Q: Find GCD of two numbers

#Program:

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

while b:

a, b = b, a % b

print("GCD is", a)

Q: Count digits, vowels, consonants in a string

#Program

s = input("Enter a string: ")

digits = vowels = consonants = 0

for ch in s:

if ch.isdigit():

digits += 1

elif ch.isalpha():

if ch.lower() in 'aeiou':

vowels += 1

else:

consonants += 1
print("Digits:", digits)

print("Vowels:", vowels)

print("Consonants:", consonants)

Q: Check perfect number

#Program:

num = int(input("Enter a number: "))

sum = 0

for i in range(1, num):

if num % i == 0:

sum += i

print("Perfect Number" if sum == num else "Not a Perfect Number")

You might also like