0% found this document useful (0 votes)
5 views2 pages

Module Question

The document contains a Python module named 'my_module' that defines several mathematical functions, including square, cube, power, is_armstrong, is_palindrome, and is_prime. Additionally, there is an 'import.py' script that tests these functions by prompting the user for input and displaying the results. The module provides essential mathematical checks and operations on numbers.

Uploaded by

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

Module Question

The document contains a Python module named 'my_module' that defines several mathematical functions, including square, cube, power, is_armstrong, is_palindrome, and is_prime. Additionally, there is an 'import.py' script that tests these functions by prompting the user for input and displaying the results. The module provides essential mathematical checks and operations on numbers.

Uploaded by

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

module question

my_module.py

def square(n):
"""Return the square of a number."""
return n ** 2

def cube(n):
"""Return the cube of a number."""
return n ** 3

def power(n, p):


"""Return n raised to the power of p."""
return n ** p

def is_armstrong(n):
"""Check if a number is an Armstrong number."""
num_str = str(n)
num_digits = len(num_str)
sum_of_powers = sum(int(digit) ** num_digits for digit in num_str)
return n == sum_of_powers

def is_palindrome(n):
"""Check if a number is a palindrome."""
num_str = str(n)
return num_str == num_str[::-1]

def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True

import.py

import my_module

# Test the functions


number=int(input("enter a number"))

print(f"Square of {number} is: {my_module.square(number)}")


print(f"Cube of {number} is: {my_module.cube(number)}")

pow=int(input("enter the power of a number"))


print(f"{number} to the power of {pow} is: {my_module.power(number, pow)}")

# Armstrong

number1 =int(input("enter a number to check armstrong"))


if my_module.is_armstrong(number1):
print(f"{number1} is an Armstrong number")
else:
print(f"{number1} is not an Armstrong number")

#palindrome

number2 =int(input("enter a number to check palindrome"))


if my_module.is_palindrome(number2):
print(f"{number2} is a palindrome")
else:
print(f"{number2} is not a palindrome")

#prime
number3 =int(input("enter a number to check prime"))
if my_module.is_prime(number3):
print(f"{number3} is a prime number")
else:
print(f"{number3} is not a prime number")

You might also like