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

Acknowledgement (1) 1

Uploaded by

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

Acknowledgement (1) 1

Uploaded by

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

#program to check whether given number is armstrong or

not

num = input("enter an integer:")


digits= len(num)
sum = 0
for i in range(0,digits):
a = int(num[i])
sum = sum+a**digits
if sum==int(num):
print(num,'is an armstrong no.')
else:
print(num,'is not an armstrong no.')
# program to check whether the given number is even or odd

number= int(input("enter your number:"))


if number%2==0:
print(number,'even no.')
else:
print(number,'odd no.')

output:

# calculate factorial using recursion


def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)

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


print(f"Factorial of {num} is {factorial(num)}")

output:

# program to check a no. is prime or not


def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True

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


print(f"{num} is Prime" if is_prime(num) else f"{num} is not
Prime")

output:

# sum of list elements


def list_sum(lst):
return sum(lst)

numbers = list(map(int, input("Enter numbers separated by


space: ").split()))
print(f"Sum of the list elements is: {list_sum(numbers)}")

output:

# bubble sort
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr

arr = [64, 34, 25, 12, 22, 11, 90]


print("Sorted array is:", bubble_sort(arr))

output:

You might also like