Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Python program the takes a number between 1 0 and 5 0 both included from the user and classifies the number as composite
Write a Python program the takes a number between and both included from the user and classifies the number as
composite or prime and adds them to a dictionary where the number is the key and the category is the value.
Example
Enter a number: : 'Composite'
Enter a number: : 'Composite', : 'Prime'
Enter a number: is not in the range. Enter a number between and :
You will need to write at list three function for this problem.
isprimenum checks if num is prime and if so returns True
validateuserinputnum checks if user number is a valid
integer between and inclusive. If so it returns the number or continues to
ask the user to enter a valid number. Use a logic something like
while not num.isdigit or intnum not in range:
if not num.isdigit:
do something
else
do another thing
makedict will ask the user for a number, validate it check type, and adds it to the
dictionary compositeorprime and returns it
Continue adding to the dictionary as long as its size is less than
Variables:
compositeorprime, num,
# Write your code here
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started