Cs1101 learning jurnal unit 4 PDF

Title Cs1101 learning jurnal unit 4
Author ABDELRAHMAN ALI
Course U4 Programming Assignement
Institution University of the People
Pages 2
File Size 124.6 KB
File Type PDF
Total Downloads 4
Total Views 135

Summary

ecytt ygyby uh yyo u bugug ygyg uug gugggyygyt5e3wdxfcgvhbjnmlo[ipuoytrsefcghjbk...


Description

Part 1: As an exercise, use incremental development to write a function called hypotenuse that returns the length of the hypotenuse of a right triangle given the lengths of the other two legs as arguments. Record each stage of the development process as you go. def hypotenuse(x,y): return 0

This function will returns 0. However, in order to find the length of the hypotenuse we were instructed to assign 3 and 4 as an arguments which are the parameters x and y. # defining 'x' and 'y' def hypotenuse(x,y): squ_x = x**2 squ_y = y**2

# defining 'squ' squ = (squ_x+squ_y)**0.5 # defining 'squ' return squ

Now I will call the function "hypotenuse(3,4)", and the other output of two # .additional calls to hypotenuse with different arguments print("hypotenuse (3,4) is:",hypotenuse(3,4)) print("hypotenuse (12,16) is:",hypotenuse(12,16)) print("hypotenuse (18,24) is:",hypotenuse(18,24))

# and the output is: hypotenuse (3,4) is: 5.0 hypotenuse (12,16) is: 20.0 hypotenuse (18,24) is: 30.0

Part 2: Invent your own function that does some useful computation of your choosing. Do not copy the function from somewhere else. Use incremental development, and record each stage of the development process as you go. Finally, print output that demonstrates that the function works as you intended. I want to build a simple function that calculate the area of the circle inscribed in a square with the certain side length. from math import pi

def circ_area_in_sq(x): # The math.pi constant returns the value of pi: 3.141592653589793. try: x = float(x) return (pi*((x/2)**2)) except ValueError: return None print(circ_area_in_sq("no number")) print(circ_area_in_sq(7)) print(circ_area_in_sq(10))

# output None 38.48451000647496 78.53981633974483

Part 3: Describe your experience so far with peer assessment of Discussion Assignments. When I saw the feedback and rating, I received from my peers I was a bit happy even though I had a good score but I have to work harder to score higher in my subsequent peer assessment. I felt that my peer would be happy with the feedback and the rating I gave them because I gave them work of encouragement in the feedback and a very good rating also.

Reference: Downey, A. (2015). Think Python: How to Think Like a Computer Scientist. (2.ED). Green Tea Press. Needham, Massachusetts....


Similar Free PDFs