Q1.
Write a Python program (script) to input length of three
sides of a triangle (float), calculate area using Heron's
formula.
a = float(input("Enter length of first side (a): "))
b = float(input("Enter length of second side (b): "))
c = float(input("Enter length of third side (c): "))
s = (a + b + c) / 2
area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
print("Area of triangle =", area)
Q2. Write a Python program to input student details and
marks, then calculate term total and grand total.
roll = int(input("Enter Roll Number: "))
name = input("Enter Student Name: ")
wtest = float(input("Enter Weekly Test Marks (out of 40):
"))
theo = float(input("Enter Theory Marks (out of 70): "))
prac = float(input("Enter Practical Marks (out of 30): "))
ttot = theo + prac
gtot = (0.5 * wtest) + (0.8 * ttot)
print("Roll No.:", roll)
print("Name:", name)
print("Weekly Test Marks:", wtest)
print("Theory Marks:", theo)
print("Practical Marks:", prac)
print("Term Total:", ttot)
print("Grand Total:", gtot)
Q3. Write a Python program to input employee basic salary
and calculate allowances, deductions and net salary.
code = int(input("Enter Employee Code: "))
name = input("Enter Employee Name: ")
bsal = float(input("Enter Basic Salary: "))
hrent = 0.15 * bsal
perks = 0.85 * bsal
gsal = bsal + hrent + perks
pfded = 0.10 * gsal
itax = 0.10 * gsal
nsal = gsal - pfded - itax
print("Employee Code:", code)
print("Name:", name)
print("Basic Salary:", bsal)
print("House Rent:", hrent)
print("Perks:", perks)
print("Gross Salary:", gsal)
print("PF Deduction:", pfded)
print("Income Tax:", itax)
print("Net Salary:", nsal)
Q4. Write a Python program to calculate roots of a quadratic
equation.
a = float(input("Enter coefficient a: "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))
d = b**2 - 4*a*c
if d == 0:
r = -b / (2*a)
print("Real and Equal Roots:", r, "and", r)
elif d > 0:
r1 = (-b + d**0.5) / (2*a)
r2 = (-b - d**0.5) / (2*a)
print("Real and Distinct Roots:", r1, "and", r2)
else:
print("Complex Roots")