Question

In: Computer Science

1.1 Write a python in Jupiter notebook function called trng that takes three numbers x, y,...

1.1

Write a python in Jupiter notebook function called trng that takes three numbers x, y, and z, and specifies if those can form a triangle (i.e., returns the word triangle if they can, and Not a triangle otherwise).
Note: In order for three numbers to form a triangle sum of any two of them must be greater than the third one (e.g., x=1, y=2, z=4 cannot form a triangle because x+y is not greater than z even though x+z>y and y+z>x).

2.2 Write a program that gets three numbers from user and by calling the trng function you defined above specify if those numbers could be three sides of a triangle.


Example:
Enter the first number: 3.2
Enter the second number: 4
Enter the third number: 7.5
Not a triangle

Solutions

Expert Solution

Python code:

#1.1)
#trng function
def trng(x,y,z):
    #checking if the sum of any 2 side is greater than the 3rd side
    if(x+y>z and y+z>x and x+z>y):
        #trianle is returned
        return("triangle")
    else:
        #Not a trianle is returned
        return("Not a triangle")
#2.2)
#accepting x
x=float(input("Enter the first number: "))
#accepting y
y=float(input("Enter the second number: "))
#accepting z
z=float(input("Enter the third number: "))
#printing returned of trng function for x,y,z as input
print(trng(x,y,z))   


Screenshot:


Input and Output:


Related Solutions

In python of Jupiter notebook Write a python function called trng that takes three numbers x,...
In python of Jupiter notebook Write a python function called trng that takes three numbers x, y, and z, and specifies if those can form a triangle (i.e., returns the word triangle if they can, and Not a triangleotherwise). Note: In order for three numbers to form a triangle sum of any two of them must be greater than the third one (e.g., x=1, y=2, z=4 cannot form a triangle because x+y is not greater than z even though x+z>y...
Python Jupiter Notebook Write a program that keeps getting a set of numbers from user until...
Python Jupiter Notebook Write a program that keeps getting a set of numbers from user until the user enters "done". Then shows the count, total, and average of the entered numbers. Example: Enter a number: 55 Enter a number: 90 Enter a number: 12 Enter a number: done You entered 3 numbers, total is 157, average is 52.33333
Programming Python Jupiter notebook Write a Python program that gets a numeric grade (on a scale...
Programming Python Jupiter notebook Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range, it asks him/her to enter a numeric input in the correct range, instead of returning an error. Example: Enter your score: 78 Letter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter his/her favorite English saying, then counts the number of vowels in that (note that the user may type the saying using any combination of upper or lower case letters). Example: Enter your favorite English saying: Actions speak LOUDER than words. Number of wovels: 10
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and returns a new sequence that is twice the length of the parameter sequence but that contains the contents of the original in palindrome form. For example, if the sequence "super" is passed into the function, the function will return "superrepus".
'PYTHON' 1. Write a function called compute_discount which takes a float as the cost and a...
'PYTHON' 1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and...
In Python, Q. Write a function max_increase(seq) which takes as argument a sequence of numbers and...
In Python, Q. Write a function max_increase(seq) which takes as argument a sequence of numbers and returns the maximum increase from one element in the sequence to an element at a higher index. Assumptions and restrictions: The function must return a number. If there is no increasing pair in the sequence, the function should return 0. This may happen for example if the sequence is decreasing, or if it contains fewer than 2 elements. You can assume that the argument...
In python, write a function, called ThreeSum, that accepts a list of non-negative numbers as input,...
In python, write a function, called ThreeSum, that accepts a list of non-negative numbers as input, and returns the highest sum of three neighboring elements in it. Write a main method that initializes the following five lists, gets the ThreeSum result for all of them using the above function, and prints the result to the screen. Example of the output: List 1: [4,5,4,5] , Three sum = 14 List 2: [7] , Three sum = 7 List 3: [ ]...
Write a python function image compress() that takes one argument called filename, which is the name...
Write a python function image compress() that takes one argument called filename, which is the name of a file that contains a N × N (N-pixel by N-pixel) “grayscale bitmap image”. A “grayscale bitmap image” is an image of the following form where every pixel contains a grayscale color value between 0 − 255 (inclusive). Colour value 0 means that pixel should appear completely black and color value 255means completely white. Any other value in between stands for different shades...
Create a function called merge that takes two int vectors (x and y) as argument and...
Create a function called merge that takes two int vectors (x and y) as argument and returns an int vector (z) that is the result of merging the two vectors x and y. Here is an example to explain how the merge function works: If the vector x has the following values: 1 2 3 4 5, and the vector y has the following: 6 7 8 9 10 11 12, then the merging vector z will have: 1 6...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT