Question

In: Computer Science

Write a design algorithm and a python program which asks the user for the length of...

Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2 of TriangleA: 3 Enter side3 of TriangleA: 4 Enter side1 of TriangleB: 1 Enter side2 of TriangleB: 2 Enter side3 of TriangleB: 2 perimeter of TriangleA: 9.00 perimeter of of TriangleB: 5.00 perimeter of TriangleA is greater than perimeter of TriangleB. or Enter side1 of TriangleA: 2 Enter side2 of TriangleA: 1 Enter side3 of TriangleA: 3 Enter side1 of TriangleB: 1 Enter side2 of TriangleB: 2 Enter side3 of TriangleB: 3 perimeter of TriangleA: 6.00 perimeter of of TriangleB: 6.00 perimeter of TriangleA is equal to perimeter of TriangleB. PYTHON!!

Solutions

Expert Solution

Aside1 = float(input("Enter side1 of TriangleA:"))
Aside2 = float(input("Enter side2 of TriangleA:"))
Aside3 = float(input("Enter side3 of TriangleA:"))
Bside1 = float(input("Enter side1 of TriangleB:"))
Bside2 = float(input("Enter side2 of TriangleB:"))
Bside3 = float(input("Enter side3 of TriangleB:"))
Aperimeter = Aside1+Aside2+Aside3;
Bperimeter = Bside1 + Bside2+Bside3;
# .2f means how many digit after decimal .
print("perimeter of TriangleA:%.2f" %Aperimeter)
print("perimeter of TriangleB:%.2f" %Bperimeter)
if Aperimeter==Bperimeter:
    print("perimeter of TriangleA is equal to perimeter of TriangleB.");
elif Aperimeter>Bperimeter:
    print("perimeter of TriangleA is greater than perimeter of TriangleB.");
else:
    print("perimeter of TriangleA is less than perimeter of TriangleB.");
   

In the code there are variables of sides of trangle A and B which is taking float values from the use and computing the result according to given in the quesiton.


Related Solutions

Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
Write a python program which asks the user to enter a positive number that is greater...
Write a python program which asks the user to enter a positive number that is greater than 30 called, “num2” and then does the following: o 1) Print all numbers between 1 and “num2” that are divisible by 2 and 3. o 2) Print all numbers between 1 and “num2” that are either divisible by 6 or 7. o 3) Print all numbers between 1 and “num3” that is not divisible by 5
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Write a complete Python program that asks the user for a line of text (not just...
Write a complete Python program that asks the user for a line of text (not just a single word), and then tells the user whether the string is a palindrome (same forward and backward) if you ignore case and non-alphabetic characters. The following methods and functions may be useful: str.upper(), str.isalpha() -> bool, reversed(str) -> sequence, str.find(str) -> int, str.replace(str, str), str.center(int). Unless otherwise specified, they all return a string.
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
[4 marks] Write a Python program for a “Deliver-Eat!” app that asks the user for their...
[4 marks] Write a Python program for a “Deliver-Eat!” app that asks the user for their tip amount. If the user tips less than $5 they should receive a 1-star rating. If the user tips $5 or more they should receive a 5-star rating. Your program should match the output below. User input is in red. >>> How much would you like to tip? $4.50 >>> Here is your rating! * >>> How much would you like to tip? $7.20...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT