Question: CS 1 2 0 - Yoo Project 1 Fall 2 0 2 4 DUE: 1 1 : 5 9 P . M . on September

CS120- Yoo Project 1 Fall 2024
DUE: 11:59 P.M. on September 22(Sunday)
PROJECT DESCRIPTION:
Implement your Math Function Library (MathLibrary.py) and a driver program Project1.py to test your
own math functions.
MathLibrary.py includes following three math functions defined by you:
(1) MySqrt - def MySqrt (x):
To calculate square root of a positive number (x) using Newtons method (see pseudocode below):
guess = x/2
newGuess = guess (guess*guess x)/(2*guess)
while abs(guess newGuess)>0.000001
guess = newGuess
newGuess = guess (guess*guess x)/(2*guess)
return newGuess
(2) x_to_n def x_to_n (x, n)
To compute x to the nth power (i.e. xn). Two input parameters: a float value x and an integer n (see
pseudocode below):
if n >0
set product =1
for k in the range 1,2,3,...,n
product = product * x
return product
if n <0(recall that x-n is simply 1/xn)
set product =1
for k in range n, n-1,...,-1
product = product *1/x
return product
(3) MyLength def MyLength (x1, y1, x2, y2)
To compute the distance between two points(x1,y1) and (x2,y2) using the Euclidean distance formula,
d= sqrt((x1-x2)2+(y1-y2)2)
2
Project1.py includes menu() function below and test codes by calling functions in
MathLibrary.py
import MathLibrary
def menu ():
print ()
print (1: find the square root of the number: )
print (2: find the x to the nth power: )
print (3: find the length of line segment: )
print (4: QUIT)
choice = int (input (Choose your option: )
return choice
choice = menu ()
# test the functions you defined in your Math library as below (pseudocode):
while choice is not 4:
if choice is 1
display the result of the square root of 30
else if choice is 2
display the result of 94
else if choice is 3
display the length of line between point (1,1) and (3,4)
else if choice is 4
break
else
print Invalid input. Try again.
GRADING:
Your program will be graded not only on meeting the stated requirements of the project, but also on
design quality and programming style. Program should be defect-free (no error). A late project may be
accepted with a penalty of 10% per day.
Collaboration on project or copying from Internet is not allowed and is considered as cheating. You are
required to observe the University and Departmental policies on academic honesty. Any requests for
special consideration relating to late projects must be discussed with and approved by the instructor in
advance.
SUBMISSION:
The project submission should in a zip file format including the files:
source code (MathLibrary.py, Project1.py)
Snapshot of the output after running the test cases above
Use a name convention of CS120_Project1_yourLastName(ex. CS120_Project1_Yoo)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!