Answered step by step
Verified Expert Solution
Link Copied!

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 10 and 50 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: 10--->{10 : 'Composite'}
Enter a number: 23---->{10 : 'Composite', 23 : 'Prime'}
Enter a number: 9---->9 is not in the range. Enter a number between 10 and 50:
You will need to write at list three function for this problem.
1. is_prime(num)---> checks if num is prime and if so, returns True
2. validate_user_input(num)---> checks if user number is a valid
integer between 10 and 50 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 int(num) not in range(10,51):
if not num.isdigit():
do something
else
do another thing
3. make_dict()---> will ask the user for a number, validate it, check type, and adds it to the
dictionary composite_or_prime and returns it.
Continue adding to the dictionary as long as its size is less than 10.
Variables:
composite_or_prime, num,
"""
# Write your code here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions