can someone help me out with this function program in python please Your mission
ID: 3630317 • Letter: C
Question
can someone help me out with this function program in python please
Your mission is to write a program that examines positive integers within a range that the user specifies and categorizes them as follows:
ODD or EVEN
PRIME or COMPOSITE -- a prime number is an integer greater than one that is divisible only by itself and one. Any number that is not "prime" is "composite". 1 is neither prime nor composite by definition
PERFECT / ABUNDANT / DEFICIENT --- as described above
SQUARE -- as described above
TRIANGULAR -- as described above
You may assume that the user, a.k.a. your grader, will enter integers for this program.
The results are to be printed out in a well-formatted table. See the sample run below.
Implementation
Your program MUST include the following functions.
Do NOT change the function names or parameters in the function headers given below.
Since this is a math-related project it's appropriate for us to use n as a variable name for an integer. When a variable is holding the value of something, it's important to name that variable with a meaningful name for what's being held, but just an integer, is okay to be called n. Similarly, it's okay to use a and b
You may choose to use more functions if you wish, but these are sufficient. All predicate functions, by definition, must return True or False. You have some flexibility in implementing the other functions.
view sourceprint?
def main():
# is the skeleton of the program
def printGreeting():
# explains the program to the user
def printTableHeading():
# prints the heading of the table
def isOdd(n):
# a predicate function that returns True if n is odd
# and returns False if not.
def isPrime(n):
# a predicate function that returns True if n is prime,
#and False if not
def checkForPerfect(n):
# classifies n as "perfect", "abundant" or "deficient".
# A different value is returned for each category.
def sumDivisors(n):
# returns the sum of the divisors of n.
def isDivisor(a, b):
# a predicate function that returns True if b is
# a divisor of a, and False if not.
def isSquare(n):
# returns True if n is a perfect square, False if not.
def isTriangular(n):
# returns True if n is a triangular number, False if not.
def printTableLine(n, odd, prime, perfect, square, triangular):
# prints the information for one number on one line of the table.
Explanation / Answer
def main( import mathfirstNum = 0secondNum = 0n = 0odd = 0prime = 0perfect = 0square = 0perfect = 0square = 0triangular = 0printGreeting()firstNum = input('Please enter an integer between 1 and 100000: ')secondNum = input('Please enter an interger greater than your pervious but not larger than 100000: ')for n in range(firstNum, secondNum + 1):isOdd(n)isPrime(n)checkForPerfect(n)isSquare(n)isTriangular(n)printTablLine(n, odd, prime, perfect, square, triangular)main()printGreeting():print 'This program classifies positive integers as Odd/Even,'print 'Prime/Composite, Perfect/Abundant/Deficient, Square,'print 'and Triangular.'printprint 'You will now get to choose the range of positive intergers'print 'that you would like to see classified.'printdef printTableHeading():def isOdd(n):if firstNum % 2 == 0:return Falseelse:return Truedef isPrime(n):if n == 2:return Truefor divisor in range(3, int(math.sqrt(n)), 2):if n % divisor == 0:return Falsereturn Truedef checkForPerfect(n):sum = 0if n % == 0:sum +=if sum == n:return 'Perfect'elif sum > n:return 'Abundant'else:return 'Abundant'else:return 'Deficient'def sumDivisors(n):# returns the sum of the divisors of n.def isDivisor(a, b):# a predicate function that returns True if b is a divisor of a, and False if not.def isSquare(n):# returns True if n is a perfect square, False if not.def isTriangular(n):# returns True if n is a triangular number, False if not.def printTableLine(n, odd, prime, perfect, square, triangular):# prints the information for one number on one line of the table.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.