(Solved) : Write Python Module Functions Determine Properties Given Integers Use Functions Collect St Q37201147 . . .
Write a Python Module with some functions that determineproperties of given integers, and use these functions to collectstatistics about a series of numbers input by the user.
To start, create a python file for your module. Name it asLastNameFirstName_num_stats.py. It will contain the followingfunctions:
# is_odd
# Input: number (int)
# Processing: Test to see if that number is odd
# Output: True if it is odd, False otherwise (boolean)
# is_prime
# Input: number (int)
# Processing: Test to see if that number is prime
# Output: True if it is prime, False otherwise (boolean)
# is_square
# Input: number (int)
# Processing: Test to see if that number is a perfect square.
# Output: True if it is a perfect square, False otherwise(boolean)
# length
# Input: number (int)
# Processing: Count the number of digits in int
# Output: The number of digits in int
Then create another file for your main program. This shouldfollow the usual assignment file naming pattern:LastNameFirstName_assign8_part2.py. Now write a program that usesthe above four functions. Your program will:
- Allow the user to input a series of integers. Valid inputs arepositive integers or zero. Use the sentinel “end” to end the input.(Be careful! You can’t immediately convert the input to an int –you have to test for the sentinel first.)
- At the end, output a report with the following statistics:
- How many numbers
- The largest number
- The smallest number
- The average of all of the numbers (rounded to two decimalplaces)
- The number of digits in the shortest number
- The number of digits in the longest number
- How many of the numbers were odd
- How many were primes
- How many were perfect squares
Example runs:
Enter a positive integer (or ‘end’ to end): -34
Invalid entry. Must be 0 or positive.
Enter a positive integer (or ‘end’ to end): end
You entered no valid numbers.
Enter a positive integer (or ‘end’ to end): 4
Enter a positive integer (or ‘end’ to end): 0
Enter a positive integer (or ‘end’ to end): -17
Invalid entry. Must be 0 or positive.
Enter a positive integer (or ‘end’ to end): 17
Enter a positive integer (or ‘end’ to end): 67
Enter a positive integer (or ‘end’ to end): 64
Enter a positive integer (or ‘end’ to end): 937
Enter a positive integer (or ‘end’ to end): 89732471
Enter a positive integer (or ‘end’ to end): end
You entered 7 numbers.
Largest: 89732471
Smallest: 0
Average: 12819080.00
Shortest: 1 digit
Longest: 8 digits
Num. Odd: 4
Num. Primes: 3
Num. Squares: 3
HINTS:
- You must handle the case where the user enters no valid numbers(to avoid division-by-zero errors)!
- You can format the output so all the data aligns properly tothe right, by using the length of the longest number. This meansyou will have to generate your format string on-the-fly in yourcode. And remember to include room for the decimal places of theaverage (so, use the length of the longest number + 2 as the columnwidth.)
- There is more than one way to get the length of a number. Youcan do it using math, or by converting the number to another datatype that you already know how to get the length of.
- You do not need to store all of the numbers that theuser enters in order to solve this problem! Do not use lists orlists functions (we haven’t learned them yet)!
- Note that 0 is counted as a perfect square (some would arguethat it isn’t, but for us it doesn’t matter.).
Expert Answer
Answer to Write a Python Module with some functions that determine properties of given integers, and use these functions to collec…
OR