Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code in python 3.5 or above rectangle(perimeter, area) Returns the longest side of the rectangle with given perimeter and area if and only if both

image text in transcribed

image text in transcribed

image text in transcribed

code in python 3.5 or above

rectangle(perimeter, area) Returns the longest side of the rectangle with given perimeter and area if and only if both sides are integer lengths. In a rectangle perimeter = 2w + 2h area = wh Hints: The built-in round( number) function rounds a number to the nearest integer. To do integer division (also known as floor division), use the // operator. Floor division, as opposed to true division, discards any fractional result from the output. the built-in float.is integer() method returns True if the float instance is finite with integral value, and False otherwise Preconditions: Inputs perimeter The perimeter of the rectangle expressed as an integer. The area of the rectangle expressed as an integer. area Outputs The longest side length for the rectangle that meets the given requirements. bool False is returned if no rectangle exists that meets the requirements. Examples: >>> rectangle(14, 10) 5 >>> rectangle(25, 25) False Side rectangle frequency(numList) Returns the most frequent item in numList and a dictionary with the frequency count of each item in the list. When more than one item has the same frequency, it returns the first item with that frequency in numList as the most frequent item. You may assume numList is a non-empty Python Tist, but you cannot make assumptions about the contents in the list. You might use the count method, but you are not allowed to use any other Python libraries such as Counter, mode, etc., or to use str() to convert data to string. Preconditions: Inputs list numList Non-empty list of elements Output many, dict First value is the most frequent item in numList and preserves its data type. Second value is a dictionary with the frequency count of each item in numList Example >>> frequency ([3, 7, 5, 5, 7, 7, 5]) (7, 3: 1, 7: 3, 5: 2}) >>> frequency ([3, 7', 5, 5.5, 7, 7, 5.5, 'a', 3, 'a', 'a', 'A']) ('a', {3: 2, 7: 2, 5: 1, 5.5: 2, 7: 1, 'a': 3, 'A': 1}) >>> answer=frequency ([6, 5, 7, 7, 7, 5, 5, 5]) >>> answer[0] 5 >>> answer [1] (6: 1, 5: 4, 7: 3} dictionare un sorted collections uniqueDigit(num) Returns a boolean value that determines whether the largest digit in num appears only once. You can assume num is a positive integer. You are not allowed to cast num to a string, str(num), to traverse or process the number. Using floor division () and modulo (%) could be helpful here. Floor division by 10 removes the rightmost digit (456//10 = 45), while modulo 10 returns the rightmost digit (456%10 = 6) Preconditions: Inputs A positive integer Output bool Sum of the digits of num. Example: >>> uniqueDigit(123132) False Largest appears todice >>> uniqueDigit(7264578364) True Sonce >>> uniqueDigit(2) True >>> uniqueDigit(444444) False

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

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions