Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
