Learning Journal 4
docx
keyboard_arrow_up
School
University of the People *
*We aren’t endorsed by this school
Course
CS 1101
Subject
Mathematics
Date
Feb 20, 2024
Type
docx
Pages
3
Uploaded by SuperHumanSheep3607
First I would make a function to define hypotenuse:
Def hypotenuse(base,per):
Return 0.0
Print (hypotenuse (3,4))
Output
:
0.0
If 0.0 is retuned after I call the function, then I would continue with the calculation:
import math
def hypotenuse(base, per):
h=math.sqrt(base ** 2 + per ** 2)
print(h)
hypotenuse(3, 4)
Output
:
5.0
Then I would add return instead of print
Import math
Def hypotenuse (base,per):
H=math.sqrt(base**2+per2)
Return h
Print(hypotenuse(3,4))
Output:
5
Here is the function that calls two other arguments:
import math
def hypotenuse(base, per):
h=math.sqrt(base ** 2 + per ** 2)
return h
print("Hypotenuse is: "+str(hypotenuse(3, 4)))
print("Hypotaneous is: "+str(hypotenuse(20, 7)))
print("Hypotaneous is: "+str(hypotenuse(16, 81)))
Outputs
:
Hypotenuse is: 5.0
Hypotaneous is: 21.18962010041709
Hypotaneous is: 82.56512580987206
Part 2:
To start I’d create my function and test to see if it works.
def puppy_dog(num1,num2):
return 0.0
print (puppy_dog(1,2))
Output
:
0.0
Since the function I made works so far I’ll add more to it.
def puppy_dog(num1, num2):
if(num1>num2):
print("dogs are better than cats")
elif(num1==num2):
print("unless you're a cat person")
else:
print("actually, they're both pretty great")
puppy_dog(29,17)
puppy_dog(45,45)
puppy_dog(14,98)
The function takes the two numbers in input and prints a statement depending on the
numbers entered. In the first set of numbers, if the first number is greater than the second,
the following statement is printed “dogs are better than cats”. In the second set of
numbers, if both numbers are the same the statement “unless you’re a cat person” is
printed. For the third set of numbers, as long as the first number isn’t greater than the
second and they don’t equal each other “actually, they’re both pretty great” will be
printed.
Output
:
dogs are better than cats
unless you're a cat person
actually, they're both pretty great
Since 29 is larger than 17 “dogs are better than cats” will be printed
Since 45 is equal to 45 “unless you’re a cat person” will be printed
Since 14 is neither larger or equals 98 “actually, they’re both great” will be printed
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help