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:
Part 3: More Numeric Analysis Now add three more functions to the num_stats module you created...
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. 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...
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 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 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 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() 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 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())
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 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...