Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
CMPSC-132: Programming and Computation II
Homework 1 (100 points) Due date: May 30th, 2021, 11:59 PM EST Goal: Revise your Python concepts and using them to solve problems using Python’s built-in data types General instructions: • The work in this assignment must be your own original work and be completed alone. • The instructor and course assistants are available on Teams and with office hours to answer any questions you may have. You may also share testing code on Teams. • A doctest is provided to ensure basic functionality and may not be representative of the full range of test cases we will be checking. Further testing is your responsibility. • Debugging code is also your responsibility. • You may submit more than once before the deadline; only the latest submission will be graded. Assignment-specific instructions: • Download the starter code file from Canvas. Do not change the function names or given starter code in your script. • Each question has different requirements, read them carefully and ask questions if you need clarification. No credit is given for code that does not follow directions. • If you are unable to complete a function, use the pass statement to avoid syntax errors Submission format:
• Submit your HW1.py file to the Homework 1 Gradescope assignment before the due date.
• As a reminder, code submitted with syntax errors does not receive credit, please run your file before submitting. Section 1:
Overview of functions Points Name Input type Output type 15 rectangle(perimeter, area) int,
int int/bool 20 frequency(numList) list many, dict 20 successors(file) str dict 15 isSorted(num) int bool 15 hailstone(num)
list list 15 largeFactor(num) int int Section 2: Function details 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 = 2+ 2ℎ = ∗ ℎ 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 int perimeter The perimeter of the rectangle expressed as an integer. int area The area of the rectangle expressed as an integer.
Outputs int The longest side length for the rectangle that meets the given requirements.
False False is returned if no rectangle exists that meets the requirements. Examples: >>> rectangle(14, 10) #
Represents a 2x5 rectangle 5 # 5 is the larger of the two sides >>> rectangle(25, 25) # Represents a 2.5x10 rectangle False # 2.5 is not an int Section