Python Ex4
Python Ex4
4
User defined function Reg.No: URK23CS7103
06.02.24
1. Write a python program to check whether a number is a palindrome or not using a function.
Aim:
To Write a python program to check whether a number is a palindrome or not using a function.
Algorithm:
Program:
def is_palindrome(num):
original_num = num
reverse_num = 0
if original_num == reverse_num:
return True
else:
return False
if is_palindrome(num):
print(num, "is a palindrome.")
else:
print(num, "is not a palindrome.")
Output:
Result:
Thus, the program was successfully excuted
1
2. .Write a python program to check Armstrong number using functions.
Algorithm:
Program:
def is_armstrong(num):
num_str = str(num)
num_digits = len(num_str)
sum_of_cubes = 0
for digit in num_str:
sum_of_cubes += int(digit) ** num_digits
if sum_of_cubes == num:
return True
else:
return False
num = int(input("Enter the number to
find to check wheather the give
number is Armstrong or not: "))
if is_armstrong(num):
print(The entered number is Armstrong
number")
else:
print(num, "is not an Armstrong number")
Output:
Result:
Hence the output is verified and excecuted.
2
3. Write python functions to print the no. of uppercase, lowercase, and whitespaces.
Aim: To Write python functions to print the no. of uppercase, lowercase, and whitespaces.
Algorithm:
Program:
def count_chars(string):
uppercase_count = 0
lowercase_count = 0
whitespace_count = 0
print("Uppercase:", uppercase_count)
print("Lowercase:", lowercase_count)
print("Whitespaces:", whitespace_count)
Output:
Result:
Hence the output is verified and excecuted
3
4