Sunday, 14 November 2021

To calculate profit-loss for a given Cost and Sell Price.

 # Python Program to Calculate Profit or Loss

 
actual_cost = float(input(" Please Enter the Actual Product Price: "))
sale_amount = float(input(" Please Enter the Sales Amount: "))
 
if(actual_cost > sale_amount):
    amount = actual_cost - sale_amount
    print("Total Loss Amount = {0}".format(amount))
elif(sale_amount > actual_cost):
    amount = sale_amount - actual_cost
    print("Total Profit = {0}".format(amount))
else:
    print("No Profit No Loss!!!")

Python profit or loss output

 Please Enter the Actual Product Price: 1500
 Please Enter the Sales Amount: 1200
Total Loss Amount = 300.0

To calculate Simple and Compound interest.

 p = int(input("Enter principal amount = ")) 

r = int(input("Enter the rate = "))
t = int(input("Enter time  = "))
si = (p * r * t ) / 100
com = p * ( (1 + (r / 100 ))** t ) - p
print("Simple interest = ",si)
print("Compound interest = ",com) 

To calculate perimeter/circumference and area of shapes such as triangle, rectangle, square and circle.

 import math

def area_square(a):
    area1=float(a*a);
    print("Area of square is:",area1)
def area_circle(r):
    area2=float(3.14*r*r);
    print("Area of circle is:",area2)
def area_rectangle(a,b):
    area3=float(a*b);
    print("Area of rectangle is:",area3)
def area_triangle(x,y):
    area4=float((x*y)/2);
    print("Area of triangle is:",area4)
def peri_square(a):
    peri1=float(4*a);
    print("Perimeter of square is:",peri1)
def peri_circle(r):
    peri2=float(2*3.14*r);
    print("Perimter of circle is:",peri2)
def peri_triangle(a,b):
    hypotenuse=float(math.sqrt(a*a+b*b))
    peri3=float(a+b+hypotenuse)
    print("Perimter of right angled triangle is:",peri3)
def peri_rectangle(a,b):
    peri4=float(2*(a+b))
    print("Perimter of rectangle is:",peri4)

side=float(input("enter the side of square:"))
area_square(side)
print()
peri_square(side)
radius=float(input("enter the radius of circle:"))
area_circle(radius)
peri_circle(radius)
length=float(input("enter the length of rectangle:"))
breadth=float(input("enter the breadth of rectangle:"))
area_rectangle(length,breadth)
peri_rectangle(length,breadth)
base=float(input("enter the base of right angled triangle:"))
height=float(input("enter the height of right angled triangle:"))
area_triangle(base,height)
peri_triangle(base,height)

To find the sale price of an item with a given cost and discount (%).

 

  1. price=float(input("Enter Price : "))
  2. dp=float(input("Enter discount % : "))
  3. discount=price*dp/100
  4. sp=price-discount
  5. print("Cost Price : ",price)
  6. print("Discount: ",discount)
  7. print("Selling Price : ",sp)

To find average and grade for given marks.


sub1=int(input("Enter marks of the first subject: "))

sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
    print("Grade: A")
elif(avg>=80&avg<90):
    print("Grade: B")
elif(avg>=70&avg<80):
    print("Grade: C")
elif(avg>=60&avg<70):
    print("Grade: D")
else:
    print("Grade: F")