Program 1
Program 1
1
TITLE : Program to calculate area of triangle, rectangle and circle.
Problem Description : Program calculates area of triangle, rectangle and circle and displays
area of triangle, rectangle and circle.
THEORY/ ANALYSIS :
Python Operators
Python divides the operators in the following groups:
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
/ Division x/y
% Modulus x%y
** Exponentiation x ** y
// Floor division x // y
= x=5 x=5
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
|= x |= 3 x=x|3
^= x ^= 3 x=x^3
== Equal x == y
!= Not equal x != y
not Reverse the result, returns False not(x < 5 and x < 10)
if the result is true
Identity operators are used to compare the objects, not if they are equal, but if they are actually
the same object, with the same memory location:
Operator Description Example
not Returns True if a sequence with the specified value is not present in x not in
in the object y
<< Zero fill Shift left by pushing zeros in from the right and let the leftmost bits fall
left shift off
>> Signed Shift right by pushing copies of the leftmost bit in from the left, and let
right shift the rightmost bits fall off
Print a tuple:
x = ("apple", "banana", "cherry")
print(x)
Syntax
input(prompt)
Parameter:
Prompt: A String, representing a default message (usually screen) before the input. However, it
is optional to have a prompt message.
Return: input() returns a string object. Even if the inputted value is an integer it converts it into
a string.
Example
Program
b = float(input('Enter base of a triangle: '))
h = float(input('Enter height of a triangle: '))
area = (b * h) / 2
print('The area of the triangle is %0.2f' % area)
Program
l = float(input('Enter the length of a Rectangle: '))
b = float(input('Enter the breadth of a Rectangle: '))
Area = l * b
print("Area of a Rectangle is: %.2f" %Area)
Program
PI = 3.14
radius = float(input(' Please Enter the radius of a circle: '))
area = PI * radius * radius
circumference = 2 * PI * radius
print(" Area Of a Circle = %.2f" %area)
print(" Circumference Of a Circle = %.2f" %circumference”)