Python Programming Examples Tutorial Index

Python Number Programs

This Python example code demonstrates a simple Python program to calculate the area of a triangle and print the output to the screen.



Program:

a = 20
b = 16
c = 30

#Remove comments from the bottom lines to take input from the user
#a = float(input('Enter the first side: '))
#b = float(input('Enter the second side: '))
#c = float(input('Enter the third side: '))

#Semi-perimeter calculation
s = (a + b + c) / 2

#Area calculation
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5

#Print the output
print('The area of the triangle is %0.2f' %area)

Program Output:

The area of the triangle is 147.92


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram