Question

Part 3: More Numeric Analysis Now add three more functions to the num_stats module you created...



Part 3: More Numeric Analysis
Now add three more functions to the num_stats module you created in part 2. These will determine if a given positive integer is EVEN, PERFECT and ABUNDANT. Each of these functions should accept a single integer as an argument and return whether the integer meets the criteria for that classification. Here's some IPO notation to get you started:

# function: is_even
# input: a positive integer
# processing: determines if the supplied number is even
# output: boolean
# function: is_perfect
# input: a positive integer
# processing: determines if the supplied number is perfect. a perfect number
# is a number that is equal to the sum of its factors besides itself
# (i.e. the number 6 is perfect because 6 = 1 + 2 + 3)
# output: boolean
# function: is_abundant
# input: a positive integer
# processing: determines if the supplied number is abundant. an abundant number
# is a number that is less than the sum of its factors besides itself
# (i.e. the number 12 is abundant because 12 < 1 + 2 + 3 + 4 + 6)
# output: boolean
Next, write a program that uses the num_stats module. Your program will allow the user to analyze numbers within a given range for numbers that fit various criteria. The program should continue to execute as long as the user wishes to keep going.

You must ensure that the user enters only positive integers, and that the end number is larger than the start number.

Here's a sample running of the program:

Chart all even, odd, prime, perfect and abundant numbers within a given range.
Ready? (Enter Y or y to continue; any other value to quit.) Y

Enter starting number (positive only): -5
Invalid, try again
Enter starting number (positive only): 5
Enter ending number: 3
Invalid, try again
Enter ending number: 100



Number Even Odd Prime Perfect Abundant   
5 x x   
6 x x   
7 x x   
8 x   
9 x   
10 x   
11 x x   
12 x x   
13 x x   
14 x   
15 x   
16 x   
17 x x   
18 x x   
19 x x   
20 x x   
21 x   
22 x   
23 x x   
24 x x   
25 x   
26 x   
27 x   
28 x x   
29 x x   
30 x x   
31 x x   
32 x   
33 x   
34 x   
35 x   
36 x x   
37 x x   
38 x   
39 x   
40 x x   
41 x x   
42 x x   
43 x x   
44 x   
45 x   
46 x   
47 x x   
48 x x   
49 x   
50 x   
51 x   
52 x   
53 x x   
54 x x   
55 x   
56 x x   
57 x   
58 x   
59 x x   
60 x x   
61 x x   
62 x   
63 x   
64 x   
65 x   
66 x x   
67 x x   
68 x   
69 x   
70 x x   
71 x x   
72 x x   
73 x x   
74 x   
75 x   
76 x   
77 x   
78 x x   
79 x x   
80 x x   
81 x   
82 x   
83 x x   
84 x x   
85 x   
86 x   
87 x   
88 x x   
89 x x   
90 x x   
91 x   
92 x   
93 x   
94 x   
95 x   
96 x x   
97 x x   
98 x   
99 x   
100 x x   


Chart all even, odd, prime, perfect and abundant numbers within a given range.
Ready? (Enter Y or y to continue; any other value to quit.) n

Goodbye!
Note: you will want to write additional "helper" functions for your program. For example, the options above all require the user to supply a range of numbers to analyze. You can probably write a function that does this so you don't have to continually copy and paste the same code over and over again.

This program should be named as follows: LastNameFirstName_assign6_part3.py (for example, "KappCraig_assign6_part3.py")

Also remember to turn in your module file (LastNameFirstName_num_stats.py)! You can use the same module file for both parts 2 and
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In this problem given , you said that add three functions to num_stats module created in part 2 , but part 2 is not given.

So,I solve the problem with given requirements.

Code:

count_factor = 0 #global variable
def is_even(n): #function to know number is even or not
if(n%2==0):
return True
else:
return False
def is_perfect(n): #function to know Perfect or not
factor = 0
count = 0
for i in range(1,n):
if(n%i==0):
count = count+1 #counting factors
factor = factor + i #adding factors
global count_factor
count_factor = count
if(factor == n):
return True
else:
return False
def is_abundant(n): #function to know Abundant or not
factor =0
for i in range(1,n):
if(n%i==0):
factor =factor+i
if(n<factor):
return True
else:
return False

#declaring lists
Even_number = []
Odd_number = []
Prime_number = []
Perfect_number = []
Abundant_number = []
while(1): #infinite loop
print("\nReady? (Enter Y or y to continue; any other value to quit.) :")
f = input(); #asking input
if(f=='y' or f=='Y'):
while(1):
s = int(input("Enter starting number(positive only): "))
if(s<0): #checking condition
print("Invalid,try again")
else:
break
while(1):
e =int(input("Enter ending number: "))
if(s<e): #checking condition
break
else:
print("Invalid,try again")
for i in range(s,e+1):
if(is_even(i)): #calling the function
Even_number.append(i)
else:
Odd_number.append(i)
if(is_perfect(i)): #calling the function
Perfect_number.append(i)
if(count_factor==1):
Prime_number.append(i)
if(is_abundant(i)): #calling the function
Abundant_number.append(i)
  
#printing the lists
print("\nEven Numbers = ",end="")
print(Even_number)
print("Odd Numbers = ",end="")
print(Odd_number)
print("Prime Numbers = ",end="")
print(Prime_number)
print("Perfect Numbers = ",end="")
print(Perfect_number)
print("Abundant Numbers = ",end="")
print(Abundant_number)
else:
print("\nGoodbye!")
break

Code images:

Output images:

Add a comment
Know the answer?
Add Answer to:
Part 3: More Numeric Analysis Now add three more functions to the num_stats module you created...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • 4. Write a logical function perfect Square that receives a positive integer number and checks if ...

    write the code in C please 4. Write a logical function perfect Square that receives a positive integer number and checks if it is a perfect square or not. Note: perfect square numbers are 4, 9,16,25,36 etc.... Write a main function that makes use of the perfect Square function to find and print all perfect squares between nl and n2. nl and n2 are end values of a range introduced by the user. ■ (inactive CAT EXE) Enter end values...

  • A positive integer is said to be a perfect number if it equals the sum of...

    A positive integer is said to be a perfect number if it equals the sum of its positive divisors (excluding the number itself). As an example, 6 is aperfect number because its divisors, 1, 2, and 3 sum up to 6. The first four perfect numbers are 6, 28, 496, 8128. Write a C program that asks the user to enter a number and checks if the number is perfect. Your program should run interactively until the user quits. Try...

  • Using Python: A Prime number is an integer greater than 1 that cannot be formed by...

    Using Python: A Prime number is an integer greater than 1 that cannot be formed by multiplying two smaller integer other than 1 and itself. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1. In this question you will write a program that takes a sequence of integers from the user and display all the prime numbers contained in that sequence. We will separate this question in...

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI()...

    PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI() This function prints out your name and lists any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and prints out a message indicating if the number is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one...

  • 2. Create the program guessgame.py discussed in the video in module 1. Make sure you can...

    2. Create the program guessgame.py discussed in the video in module 1. Make sure you can run it without syntax errors.3. Modify that program so that the user is asked to think of a secret number and the computer guesses that number. Here is the interaction: 1. The computer asks the user for the range.2. The user inputs the lowest and highest numbers in the range. The USER thinks of a secret number in that range. 3. The computer tries...

  • 4. the algorithims for sorting numbers should be managed in separate functions (e.g., sortAscending() and sortDescending())...

    4. the algorithims for sorting numbers should be managed in separate functions (e.g., sortAscending() and sortDescending()) Create a Kotlin console program that satisfies the following 1. The program prompts a user to enter a number that is used to create an array with the number of elements. 2. The program asks the user to enter a series of numbers, and the numbers are to be entered and stored in the array 3. The program asks the user to select the...

  • Assignment Develop a program to analyze one or more numbers entered by a user. The user...

    Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT