H/w question 6
Create a program in Python, called Tri-Calculator, that uses a function to calculate the area of a triangle given the base and height measurements. Use the below function to do your calculation:
def area_of_triangle (base, height); return 0.5 * base * height
The program should receive the base and the height from the user. Once the user enter a base greater than the height the program should give the user another attempt to enter a base and a height. The program only give the user three attempts to enter the correct base and height on the third attempt the program should display the below message:
"Your 3 attempts is up, try again later"
If the user enters a base less than height, the program should display the correct triangle area using the given function.
(it should contain a function, loop, if statement and sentinel value)
def area_of_triangle(base, height):
return 0.5 * base * height
attempts =3
base=0
height=0
isWrong=True
while(attempts>0 and isWrong):
base=int(input("Enter base: "))
height=int(input("Enter height: "))
isWrong=False
attempts-=1
if(base>height):
isWrong=True
else:
attempts=3
if attempts==0:
print("Your 3 attempts is up, try again later")
else:
area=area_of_triangle(base, height)
print(f"The triangle area is: {area}")
Comments
Leave a comment