Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON3; DO NOT IMPORT ANY PACKAGES IMPORTANT REQUIREMENTS: - When a question requires assert statements : write assert statements to prevent any input that may

PYTHON3; DO NOT IMPORT ANY PACKAGES

IMPORTANT REQUIREMENTS:

- When a question requires assert statements: write assert statements to prevent any input that may corrupt your code, including arguments in invalid type, and arguments that do not fit the logic.

- When a question requires list comprehension: you should not use explicit loops, including for-loop and while-loop, in this question. Instead, express the loop logic with list comprehension.

FOLLOW THE REQUIREMENTS IN THE GIVEN QUESTIONS; NO CREDIT WILL BE GIVEN OTHERWISE.

image text in transcribed

Write a function that finds the greatest single digit divisor (integers from 1 to 9) that each whole number from lower to upper (both integer, both inclusive) is divisible by. Return a dictionary with keys being each number from lower to upper and their values being the highest divisor. Requirements: assert statements, list comprehension Construct the returned dictionary with dictionary comprehension (will be explained in the discussion), which is a dictionary version of list comprehension. The format is: {key : value for ... in ...}. def find_greatest_divisor (lower, upper): >>> find_greatest_divisor (20, 27) {20: 5, 21: 7, 22: 2, 23: 1, 24: 8, 25: 5, 26: 2, 27: 9} >>> find_greatest_divisor(1, 10) {1: 1, 2:2, 3: 3, 4: 4, 5: 5, 6:6, 7: 7, 8: 8, 9: 9, 10: 5} >>> find_greatest_divisor(11, 19) {11: 1, 12: 6, 13: 1, 14: 7, 15: 5, 16: 8, 17: 1, 18: 9, 19: 1} >>> find_greatest_divisor (98, 25) Traceback (most recent call last): AssertionError # YOUR CODE GOES 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

Step: 3

blur-text-image

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions