Wednesday, December 2, 2026

CLASS 10 COMPUTER SCIENCE – PYTHON PROGRAMMING: COMPLETE QUESTION BANK AND ANSWER KEY (70 PROGRAMS USING USER-DEFINED FUNCTIONS)

 

CLASS 10 COMPUTER SCIENCE – PYTHON PROGRAMMING: COMPLETE QUESTION BANK AND ANSWER KEY (70 PROGRAMS USING USER-DEFINED FUNCTIONS)

GROUP A: BASIC MATHEMATICAL OPERATIONS

Question 1. Addition of Two Numbers

Write a Python program using a user-defined function to input two numbers from the user and calculate and display their sum.

Answer:

def add(a, b):
    s = a + b
    return s

x = float(input("Enter first number: "))
y = float(input("Enter second number: "))

result = add(x, y)
print("Sum =", result)

Question 2. Subtraction of Two Numbers

Write a Python program using a user-defined function to input two numbers from the user and calculate and display their difference.

Answer:

def subtract(a, b):
    d = a - b
    return d

x = float(input("Enter first number: "))
y = float(input("Enter second number: "))

result = subtract(x, y)
print("Difference =", result)

Question 3. Multiplication of Two Numbers

Write a Python program using a user-defined function to input two numbers from the user and calculate and display their product.

Answer:

def multiply(a, b):
    p = a * b
    return p

x = float(input("Enter first number: "))
y = float(input("Enter second number: "))

result = multiply(x, y)
print("Product =", result)

Question 4. Division of Two Numbers

Write a Python program using a user-defined function to input two numbers and calculate their quotient. Return and display the result. Assume that the second number is not zero.

Answer:

def divide(a, b):
    q = a / b
    return q

x = float(input("Enter first number: "))
y = float(input("Enter second number: "))

result = divide(x, y)
print("Quotient =", result)

Question 5. Quotient and Remainder of Two Numbers

Write a Python program using a user-defined function to input two integers and calculate their quotient and remainder. Return both values and display the results.

Answer:

def calculate(a, b):
    q = a // b
    r = a % b
    return q, r

x = int(input("Enter first number: "))
y = int(input("Enter second number: "))

q, r = calculate(x, y)

print("Quotient =", q)
print("Remainder =", r)

Question 6. Sum, Product and Difference of Two Numbers

Write a Python program using three separate user-defined functions to calculate the sum, product and difference of two numbers. Display all the calculated results.

Answer:

def add(a, b):
    return a + b

def multiply(a, b):
    return a * b

def subtract(a, b):
    return a - b

x = float(input("Enter first number: "))
y = float(input("Enter second number: "))

print("Sum =", add(x, y))
print("Product =", multiply(x, y))
print("Difference =", subtract(x, y))

Question 7. Product and Average of Three Numbers

Write a Python program using a user-defined function to calculate and return the product of three different numbers and another user-defined function to calculate and display their average.

Answer:

def product(a, b, c):
    return a * b * c

def average(a, b, c):
    avg = (a + b + c) / 3
    print("Average =", avg)

x = float(input("Enter first number: "))
y = float(input("Enter second number: "))
z = float(input("Enter third number: "))

p = product(x, y, z)
print("Product =", p)

average(x, y, z)

Question 8. Sum and Average of Four Numbers

Write a Python program using a user-defined function to input four numbers and calculate their sum and average. Return both values and display the results.

Answer:

def calculate(a, b, c, d):
    s = a + b + c + d
    avg = s / 4
    return s, avg

a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
d = float(input("Enter fourth number: "))

s, avg = calculate(a, b, c, d)

print("Sum =", s)
print("Average =", avg)

GROUP B: SQUARE, CUBE AND ROOT

Question 9. Square of a Number

Write a Python program using a user-defined function to input a number and calculate and display its square.

Answer:

def square(n):
    return n * n

num = float(input("Enter a number: "))

result = square(num)
print("Square =", result)

Question 10. Square Using a Function

Write a Python program using a user-defined function to calculate and return the square of a number entered by the user. Display the returned value.

Answer:

def square(n):
    s = n ** 2
    return s

num = float(input("Enter a number: "))

result = square(num)
print("Square =", result)

Question 11. Cube of a Number

Write a Python program using a user-defined function to calculate and return the cube of a number entered by the user. Display the returned value.

Answer:

def cube(n):
    c = n ** 3
    return c

num = float(input("Enter a number: "))

result = cube(num)
print("Cube =", result)

Question 12. Square and Cube of a Number

Write a Python program using a user-defined function to input a number and calculate and display its square and cube.

Answer:

def calculate(n):
    s = n ** 2
    c = n ** 3
    return s, c

num = float(input("Enter a number: "))

s, c = calculate(num)

print("Square =", s)
print("Cube =", c)

Question 13. Square and Cube Using a Function

Write a Python program using a user-defined function to calculate and return both the square and cube of a number entered by the user. Display both returned values.

Answer:

def calculate(n):
    return n ** 2, n ** 3

num = float(input("Enter a number: "))

s, c = calculate(num)

print("Square =", s)
print("Cube =", c)

Question 14. Square Root of a Number

Write a Python program using a user-defined function to calculate the square root of a number entered by the user. Use the sqrt() function from the math module and display the result.

Answer:

import math

def square_root(n):
    return math.sqrt(n)

num = float(input("Enter a number: "))

result = square_root(num)
print("Square Root =", result)

Question 15. Cube Root of a Number

Write a Python program using a user-defined function to calculate and return the cube root of a number entered by the user. Display the calculated result.

Answer:

def cube_root(n):
    return n ** (1 / 3)

num = float(input("Enter a positive number: "))

result = cube_root(num)
print("Cube Root =", result)

Question 16. Squares of Three Numbers (2, 3 and 4)

Write a Python program using a user-defined function to calculate and return the squares of three numbers (2, 3 and 4). Display the returned values.

Answer:

def square(n):
    return n ** 2

a = square(2)
b = square(3)
c = square(4)

print("Square of 2 =", a)
print("Square of 3 =", b)
print("Square of 4 =", c)

Question 17. Squares of Three Numbers (2, 5 and 7)

Write a Python program using a user-defined function to calculate and return the squares of three numbers (2, 5 and 7). Store all the returned values in a single variable and display them.

Answer:

def square(n):
    return n ** 2

result = square(2), square(5), square(7)

print("Squares =", result)

GROUP C: AREA OF GEOMETRICAL SHAPES

Question 18. Area of a Square

Write a Python program using a user-defined function to calculate the area of a square. The user should input its side length. Return and display the calculated area.

Formula: A = a²

Answer:

def area(a):
    return a * a

side = float(input("Enter side of square: "))

result = area(side)
print("Area of Square =", result)

Question 19. Area of a Rectangle

Write a Python program using a user-defined function to calculate the area of a rectangle. The user should input its length and breadth. Return and display the calculated area.

Formula: A = l × b

Answer:

def area(l, b):
    return l * b

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))

result = area(length, breadth)
print("Area of Rectangle =", result)

Question 20. Area of a Rectangle Using Fixed Values

Write a Python program using a user-defined function to calculate the area of a rectangle. Use length = 5 and breadth = 8. Display the calculated area.

Formula: A = l × b

Answer:

def area(l, b):
    return l * b

result = area(5, 8)

print("Area of Rectangle =", result)

Question 21. Area of a Circle

Write a Python program using a user-defined function to calculate the area of a circle. The user should input its radius. Use π = 22/7. Return and display the calculated area.

Formula: A = (22/7) × r²

Answer:

def area(r):
    return (22 / 7) * r * r

radius = float(input("Enter radius: "))

result = area(radius)
print("Area of Circle =", result)

Question 22. Area of a Trapezium

Write a Python program using a user-defined function to calculate the area of a trapezium. The user should input the lengths of its two parallel sides and perpendicular height. Return and display the result.

Formula: A = 1/2 × (a + b) × h

Answer:

def area(a, b, h):
    return 0.5 * (a + b) * h

a = float(input("Enter first parallel side: "))
b = float(input("Enter second parallel side: "))
h = float(input("Enter height: "))

result = area(a, b, h)
print("Area of Trapezium =", result)

Question 23. Area of a Parallelogram

Write a Python program using a user-defined function to calculate the area of a parallelogram. The user should input its base and perpendicular height. Return and display the calculated area.

Formula: A = b × h

Answer:

def area(b, h):
    return b * h

base = float(input("Enter base: "))
height = float(input("Enter height: "))

result = area(base, height)
print("Area of Parallelogram =", result)

Question 24. Area of an Equilateral Triangle

Write a Python program using a user-defined function to calculate the area of an equilateral triangle. The user should input its side length. Use the math module to calculate the square root.

Formula: A = (√3/4) × a²

Answer:

import math

def area(a):
    return (math.sqrt(3) / 4) * a * a

side = float(input("Enter side: "))

result = area(side)
print("Area of Equilateral Triangle =", result)

Question 25. Area of a Rhombus

Write a Python program using a user-defined function to calculate the area of a rhombus. The user should input the lengths of its two diagonals. Return and display the calculated area.

Formula: A = (d1 × d2)/2

Answer:

def area(d1, d2):
    return (d1 * d2) / 2

d1 = float(input("Enter first diagonal: "))
d2 = float(input("Enter second diagonal: "))

result = area(d1, d2)
print("Area of Rhombus =", result)

Question 26. Area of a Triangle

Write a Python program using a user-defined function to calculate the area of a triangle. The user should input its base and perpendicular height. Return and display the calculated area.

Formula: A = 1/2 × b × h

Answer:

def area(b, h):
    return (b * h) / 2

base = float(input("Enter base: "))
height = float(input("Enter height: "))

result = area(base, height)
print("Area of Triangle =", result)

GROUP D: PERIMETER AND CIRCUMFERENCE

Question 27. Perimeter of a Square

Write a Python program using a user-defined function to calculate and display the perimeter of a square. The user should input its side length.

Formula: P = 4a

Answer:

def perimeter(a):
    return 4 * a

side = float(input("Enter side: "))

result = perimeter(side)
print("Perimeter of Square =", result)

Question 28. Perimeter of a Rectangle

Write a Python program using a user-defined function to calculate the perimeter of a rectangle. The user should input its length and breadth. Return and display the result.

Formula: P = 2(l + b)

Answer:

def perimeter(l, b):
    return 2 * (l + b)

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))

result = perimeter(length, breadth)
print("Perimeter of Rectangle =", result)

Question 29. Circumference of a Circle

Write a Python program using a user-defined function to calculate and display the circumference of a circle. The user should input its radius. Use the math module.

Formula: C = 2Ï€r

Answer:

import math

def circumference(r):
    return 2 * math.pi * r

radius = float(input("Enter radius: "))

result = circumference(radius)
print("Circumference of Circle =", result)

Question 30. Area and Perimeter of a Square

Write a Python program using a user-defined function to calculate the area and perimeter of a square. The user should input its side length. Return both values and display the results.

Formulas:

  • Area = Side × Side

  • Perimeter = 4 × Side

Answer:

def calculate(a):
    area = a * a
    perimeter = 4 * a
    return area, perimeter

side = float(input("Enter side: "))

a, p = calculate(side)

print("Area =", a)
print("Perimeter =", p)

Question 31. Area and Circumference of a Circle

Write a Python program using a user-defined function to calculate the area and circumference of a circle. The user should input its radius. Return both values and display the results. Use the math module.

Formulas:

  • Area = Ï€r²

  • Circumference = 2Ï€r

Answer:

import math

def calculate(r):
    area = math.pi * r * r
    circumference = 2 * math.pi * r
    return area, circumference

radius = float(input("Enter radius: "))

a, c = calculate(radius)

print("Area =", a)
print("Circumference =", c)

GROUP E: SURFACE AREA OF SOLIDS

Question 32. Curved Surface Area of a Cuboid

Write a Python program using a user-defined function to calculate and display the Curved Surface Area (CSA) of a cuboid. The user should input its length, breadth and height.

Formula: CSA = 2h(l + b)

Answer:

def csa(l, b, h):
    return 2 * h * (l + b)

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
height = float(input("Enter height: "))

result = csa(length, breadth, height)
print("CSA of Cuboid =", result)

Question 33. Total Surface Area of a Cuboid

Write a Python program using a user-defined function to calculate the Total Surface Area (TSA) of a cuboid. The user should input its length, breadth and height. Return and display the result.

Formula: TSA = 2(lb + bh + hl)

Answer:

def tsa(l, b, h):
    return 2 * (l * b + b * h + h * l)

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
height = float(input("Enter height: "))

result = tsa(length, breadth, height)
print("TSA of Cuboid =", result)

Question 34. Total Surface Area of a Sphere

Write a Python program using a user-defined function to calculate and display the Total Surface Area (TSA) of a sphere. The user should input its radius. Use the math module.

Formula: TSA = 4Ï€r²

Answer:

import math

def tsa(r):
    return 4 * math.pi * r * r

radius = float(input("Enter radius: "))

result = tsa(radius)
print("TSA of Sphere =", result)

Question 35. Total Surface Area of a Cube

Write a Python program using a user-defined function to calculate the Total Surface Area (TSA) of a cube. The user should input its side length. Return and display the calculated area.

Formula: TSA = 6a²

Answer:

def tsa(a):
    return 6 * a * a

side = float(input("Enter side: "))

result = tsa(side)
print("TSA of Cube =", result)

GROUP F: VOLUME OF SOLIDS AND ROOM MEASUREMENT

Question 36. Volume of a Cube

Write a Python program using a user-defined function to calculate the volume of a cube. The user should input its side length. Return and display the calculated volume.

Formula: V = a³

Answer:

def volume(a):
    return a ** 3

side = float(input("Enter side: "))

result = volume(side)
print("Volume of Cube =", result)

Question 37. Volume of a Cone

Write a Python program using a user-defined function to calculate the volume of a cone. The user should input its radius and height. Use the math module.

Formula: V = (Ï€r²h)/3

Answer:

import math

def volume(r, h):
    return (math.pi * r * r * h) / 3

radius = float(input("Enter radius: "))
height = float(input("Enter height: "))

result = volume(radius, height)
print("Volume of Cone =", result)

Question 38. Volume of a Rectangular Pyramid

Write a Python program using a user-defined function to calculate the volume of a rectangular pyramid. The user should input its length, breadth and height. Return and display the calculated volume.

Formula: V = (l × b × h)/3

Answer:

def volume(l, b, h):
    return (l * b * h) / 3

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
height = float(input("Enter height: "))

result = volume(length, breadth, height)
print("Volume of Rectangular Pyramid =", result)

Question 39. Volume of a Cuboid

Write a Python program using a user-defined function to calculate the volume of a cuboid. The user should input its length, breadth and height. Return and display the calculated volume.

Formula: V = l × b × h

Answer:

def volume(l, b, h):
    return l * b * h

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
height = float(input("Enter height: "))

result = volume(length, breadth, height)
print("Volume of Cuboid =", result)

Question 40. TSA and Volume of a Cylinder

Write a Python program using a user-defined function to calculate the Total Surface Area (TSA) and volume of a cylinder. The user should input its radius and height. Return both values and display the results. Use the math module.

Formulas:

  • TSA = 2Ï€r(r + h)

  • Volume = Ï€r²h

Answer:

import math

def calculate(r, h):
    tsa = 2 * math.pi * r * (r + h)
    volume = math.pi * r * r * h
    return tsa, volume

radius = float(input("Enter radius: "))
height = float(input("Enter height: "))

t, v = calculate(radius, height)

print("TSA of Cylinder =", t)
print("Volume of Cylinder =", v)

Question 41. Area and Volume of a Room

Write a Python program using two separate user-defined functions: one function to calculate the floor area of a room and another function to calculate its volume. Input the length, breadth and height from the user, and display both results.

Formulas:

  • Floor Area = Length × Breadth

  • Volume = Length × Breadth × Height

Answer:

def area(l, b):
    return l * b

def volume(l, b, h):
    return l * b * h

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
height = float(input("Enter height: "))

a = area(length, breadth)
v = volume(length, breadth, height)

print("Floor Area =", a)
print("Volume of Room =", v)

GROUP G: UNIT CONVERSION

Question 42. Convert Feet into Inches

Write a Python program using a user-defined function to input a length in feet and convert it into inches. Return and display the converted value.

Hint: 1 foot = 12 inches.

Answer:

def convert(feet):
    return feet * 12

f = float(input("Enter length in feet: "))

result = convert(f)
print("Length in inches =", result)

Question 43. Convert Kilometers into Meters and Centimeters

Write a Python program using a user-defined function to convert a distance given in kilometers into meters and centimeters. Return both converted values and display them.

Hints:

  • 1 km = 1000 meters

  • 1 km = 100000 centimeters

Answer:

def convert(km):
    m = km * 1000
    cm = km * 100000
    return m, cm

km = float(input("Enter distance in kilometers: "))

m, cm = convert(km)

print("Distance in meters =", m)
print("Distance in centimeters =", cm)

Question 44. Convert Centimeters into Meters and Kilometers

Write a Python program using a user-defined function to convert a length given in centimeters into meters and kilometers. Return both converted values and display them.

Hints:

  • 100 cm = 1 meter

  • 100000 cm = 1 kilometer

Answer:

def convert(cm):
    m = cm / 100
    km = cm / 100000
    return m, km

cm = float(input("Enter length in centimeters: "))

m, km = convert(cm)

print("Length in meters =", m)
print("Length in kilometers =", km)

Question 45. Convert Meters into Centimeters

Write a Python program using a user-defined function to convert a length given in meters into centimeters. Return and display the converted value.

Hint: 1 meter = 100 centimeters.

Answer:

def convert(m):
    return m * 100

m = float(input("Enter length in meters: "))

result = convert(m)
print("Length in centimeters =", result)

Question 46. Convert Kilograms into Grams and Milligrams

Write a Python program using a user-defined function to convert a weight given in kilograms into grams and milligrams. Return both converted values and display them.

Hints:

  • 1 kg = 1000 grams

  • 1 kg = 1000000 milligrams

Answer:

def convert(kg):
    g = kg * 1000
    mg = kg * 1000000
    return g, mg

kg = float(input("Enter weight in kilograms: "))

g, mg = convert(kg)

print("Weight in grams =", g)
print("Weight in milligrams =", mg)

Question 47. Convert Hours into Minutes and Seconds

Write a Python program using a user-defined function to convert time given in hours into minutes and seconds. Return both converted values and display them.

Hints:

  • 1 hour = 60 minutes

  • 1 hour = 3600 seconds

Answer:

def convert(hours):
    minutes = hours * 60
    seconds = hours * 3600
    return minutes, seconds

h = float(input("Enter time in hours: "))

m, s = convert(h)

print("Time in minutes =", m)
print("Time in seconds =", s)

Question 48. Convert Seconds into Hours, Minutes and Seconds

Write a Python program using a user-defined function to convert a given time in seconds into hours, minutes and remaining seconds. Return all three values and display them.

Hints:

  • 1 hour = 3600 seconds

  • 1 minute = 60 seconds

Answer:

def convert(total):
    hours = total // 3600
    remaining = total % 3600
    minutes = remaining // 60
    seconds = remaining % 60
    return hours, minutes, seconds

total = int(input("Enter time in seconds: "))

h, m, s = convert(total)

print("Hours =", h)
print("Minutes =", m)
print("Seconds =", s)

Question 49. Convert Nepali Rupees into Paisa

Write a Python program using a user-defined function to convert an amount given in Nepali rupees into paisa. Return and display the converted amount.

Hint: 1 Rupee = 100 Paisa.

Answer:

def convert(rupees):
    return rupees * 100

rs = float(input("Enter amount in rupees: "))

result = convert(rs)
print("Amount in paisa =", result)

Question 50. Convert Fahrenheit into Celsius

Write a Python program using a user-defined function to convert temperature from Fahrenheit into Celsius. The user should input the temperature in Fahrenheit. Return and display the converted temperature.

Formula: C = (F − 32) × 5/9

Answer:

def convert(f):
    c = (f - 32) * 5 / 9
    return c

f = float(input("Enter temperature in Fahrenheit: "))

result = convert(f)
print("Temperature in Celsius =", result)

GROUP H: DIAGONAL AND HYPOTENUSE

Question 51. Diagonal of a Rectangle

Write a Python program using a user-defined function to calculate the diagonal of a rectangle. The user should input its length and breadth. Use the math module to calculate the square root.

Formula: d = √(l² + b²)

Answer:

import math

def diagonal(l, b):
    return math.sqrt(l ** 2 + b ** 2)

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))

result = diagonal(length, breadth)
print("Diagonal of Rectangle =", result)

Question 52. Hypotenuse of a Right-Angled Triangle

Write a Python program using a user-defined function to calculate the hypotenuse of a right-angled triangle. The user should input its base and perpendicular. Use the math module.

Formula: H = √(B² + P²)

Answer:

import math

def hypotenuse(b, p):
    return math.sqrt(b ** 2 + p ** 2)

base = float(input("Enter base: "))
perpendicular = float(input("Enter perpendicular: "))

result = hypotenuse(base, perpendicular)
print("Hypotenuse =", result)

GROUP I: MARKS, PERCENTAGE AND SPEED

Question 53. Total Marks and Percentage

Write a Python program using a user-defined function to input marks obtained in five subjects and calculate the total marks and percentage. Assume that the full marks of each subject are 100. Return both values and display them.

Formulas:

  • Total Marks = Sum of Marks of Five Subjects

  • Percentage = (Total Marks / 500) × 100

Answer:

def calculate(a, b, c, d, e):
    total = a + b + c + d + e
    percentage = (total / 500) * 100
    return total, percentage

a = float(input("Enter marks in subject 1: "))
b = float(input("Enter marks in subject 2: "))
c = float(input("Enter marks in subject 3: "))
d = float(input("Enter marks in subject 4: "))
e = float(input("Enter marks in subject 5: "))

t, p = calculate(a, b, c, d, e)

print("Total Marks =", t)
print("Percentage =", p)

Question 54. Calculate Percentage of a Number

Write a Python program using a user-defined function to input a number and a percentage value. Calculate the specified percentage of the given number. Return and display the result.

Formula: Result = (Number × Percentage) / 100

Answer:

def calculate(n, p):
    return (n * p) / 100

num = float(input("Enter a number: "))
per = float(input("Enter percentage: "))

result = calculate(num, per)
print("Result =", result)

Question 55. Average Speed

Write a Python program using a user-defined function to calculate the average speed of a vehicle. The user should input the distance travelled in kilometers and time taken in hours. Return and display the average speed.

Formula: Speed = Distance / Time

Answer:

def speed(d, t):
    return d / t

distance = float(input("Enter distance in kilometers: "))
time = float(input("Enter time in hours: "))

result = speed(distance, time)
print("Average Speed =", result, "km/hr")

GROUP J: PROFIT, LOSS, DISCOUNT AND VAT

Question 56. Profit and Profit Percentage

Write a Python program using a user-defined function to calculate profit and profit percentage. The user should input the cost price and selling price. Return both values and display them.

Formulas:

  • Profit = SP − CP

  • Profit Percentage = (Profit / CP) × 100

Answer:

def calculate(cp, sp):
    profit = sp - cp
    percentage = (profit / cp) * 100
    return profit, percentage

cp = float(input("Enter cost price: "))
sp = float(input("Enter selling price: "))

p, per = calculate(cp, sp)

print("Profit =", p)
print("Profit Percentage =", per)

Question 57. Loss and Loss Percentage

Write a Python program using a user-defined function to calculate loss and loss percentage. The user should input the cost price and selling price. Return both values and display them.

Formulas:

  • Loss = CP − SP

  • Loss Percentage = (Loss / CP) × 100

Answer:

def calculate(cp, sp):
    loss = cp - sp
    percentage = (loss / cp) * 100
    return loss, percentage

cp = float(input("Enter cost price: "))
sp = float(input("Enter selling price: "))

l, per = calculate(cp, sp)

print("Loss =", l)
print("Loss Percentage =", per)

Question 58. Calculate Discount and Selling Price

Write a Python program using a user-defined function to calculate the discount amount and selling price after allowing a 10% discount on the marked price. The user should input the marked price. Return both values and display them.

Formulas:

  • Discount = (MP × 10) / 100

  • Selling Price = MP − Discount

Answer:

def calculate(mp):
    discount = (mp * 10) / 100
    sp = mp - discount
    return discount, sp

mp = float(input("Enter marked price: "))

d, sp = calculate(mp)

print("Discount =", d)
print("Selling Price =", sp)

Question 59. Calculate VAT and Total Bill

Write a Python program using a user-defined function to calculate the VAT amount and total bill after adding 13% VAT to the price of an item. The user should input the price of the item. Return both values and display them.

Formulas:

  • VAT = (Price × 13) / 100

  • Total Bill = Price + VAT

Answer:

def calculate(price):
    vat = (price * 13) / 100
    total = price + vat
    return vat, total

price = float(input("Enter price of item: "))

v, t = calculate(price)

print("VAT =", v)
print("Total Bill =", t)

Question 60. Final Bill After Discount and VAT

Write a Python program using a user-defined function to calculate the final bill after deducting a 10% discount and adding 13% VAT to the discounted price. The user should input the marked price. Return the discount, VAT and final amount and display them.

Formulas:

  • Discount = (MP × 10) / 100

  • Discounted Price = MP − Discount

  • VAT = (Discounted Price × 13) / 100

  • Final Bill = Discounted Price + VAT

Answer:

def calculate(mp):
    discount = (mp * 10) / 100
    price = mp - discount
    vat = (price * 13) / 100
    final = price + vat
    return discount, vat, final

mp = float(input("Enter marked price: "))

d, v, f = calculate(mp)

print("Discount =", d)
print("VAT =", v)
print("Final Bill =", f)

GROUP K: SIMPLE AND COMPOUND INTEREST

Question 61. Simple Interest Using Default Argument

Write a Python program using a user-defined function to calculate Simple Interest. Use a default rate of interest of 10%. The user should input the principal amount and time in years.

Formula: SI = (P × R × T) / 100

Answer:

def simple_interest(p, t, r=10):
    si = (p * r * t) / 100
    return si

p = float(input("Enter principal amount: "))
t = float(input("Enter time in years: "))

result = simple_interest(p, t)
print("Simple Interest =", result)

Question 62. Simple Interest and Total Amount

Write a Python program using a user-defined function to calculate Simple Interest and total amount. The user should input the principal amount, rate of interest and time in years. Return both values and display them.

Formulas:

  • SI = (P × R × T) / 100

  • Amount = P + SI

Answer:

def calculate(p, r, t):
    si = (p * r * t) / 100
    amount = p + si
    return si, amount

p = float(input("Enter principal amount: "))
r = float(input("Enter rate of interest: "))
t = float(input("Enter time in years: "))

si, amount = calculate(p, r, t)

print("Simple Interest =", si)
print("Total Amount =", amount)

Question 63. Compound Interest and Total Amount

Write a Python program using a user-defined function to calculate compound interest and total amount. The user should input the principal amount, rate of interest and time in years. Return both values and display them.

Formulas:

  • Amount = P(1 + R/100)^T

  • CI = Amount − P

Answer:

def calculate(p, r, t):
    amount = p * (1 + r / 100) ** t
    ci = amount - p
    return ci, amount

p = float(input("Enter principal amount: "))
r = float(input("Enter rate of interest: "))
t = float(input("Enter time in years: "))

ci, amount = calculate(p, r, t)

print("Compound Interest =", ci)
print("Total Amount =", amount)

GROUP L: SALARY AND BILL CALCULATION

Question 64. Calculate Gross Salary

Write a Python program using a user-defined function to calculate the gross salary of an employee by adding 20% allowance and 10% dearness allowance to the basic salary. The user should input the basic salary. Return and display the gross salary.

Formulas:

  • Allowance = (Basic Salary × 20) / 100

  • Dearness Allowance = (Basic Salary × 10) / 100

  • Gross Salary = Basic Salary + Allowance + Dearness Allowance

Answer:

def calculate(basic):
    allowance = (basic * 20) / 100
    da = (basic * 10) / 100
    gross = basic + allowance + da
    return gross

basic = float(input("Enter basic salary: "))

result = calculate(basic)
print("Gross Salary =", result)

Question 65. Calculate Net Salary

Write a Python program using a user-defined function to calculate the net salary of an employee after adding 15% allowance and deducting 10% tax from the basic salary. The user should input the basic salary. Return and display the net salary.

Formulas:

  • Allowance = (Basic Salary × 15) / 100

  • Tax = (Basic Salary × 10) / 100

  • Net Salary = Basic Salary + Allowance − Tax

Answer:

def calculate(basic):
    allowance = (basic * 15) / 100
    tax = (basic * 10) / 100
    net = basic + allowance - tax
    return net

basic = float(input("Enter basic salary: "))

result = calculate(basic)
print("Net Salary =", result)

Question 66. Restaurant Bill with Service Charge

Write a Python program using a user-defined function to calculate the service charge and final restaurant bill after adding a 10% service charge. The user should input the restaurant bill. Return both values and display them.

Formulas:

  • Service Charge = (Bill × 10) / 100

  • Total Bill = Bill + Service Charge

Answer:

def calculate(bill):
    service = (bill * 10) / 100
    total = bill + service
    return service, total

bill = float(input("Enter restaurant bill: "))

s, t = calculate(bill)

print("Service Charge =", s)
print("Total Bill =", t)

GROUP M: SWAPPING TWO NUMBERS

Question 67. Swap Two Numbers Using a Temporary Variable

Write a Python program using a user-defined function to swap two numbers using a temporary variable. The user should input two numbers. Return the swapped values and display them.

Answer:

def swap(a, b):
    temp = a
    a = b
    b = temp
    return a, b

x = float(input("Enter first number: "))
y = float(input("Enter second number: "))

x, y = swap(x, y)

print("After swapping:")
print("First number =", x)
print("Second number =", y)

Question 68. Swap Two Numbers Without a Temporary Variable

Write a Python program using a user-defined function to swap two numbers without using a temporary variable. The user should input two numbers. Return the swapped values and display them.

Answer:

def swap(a, b):
    a = a + b
    b = a - b
    a = a - b
    return a, b

x = float(input("Enter first number: "))
y = float(input("Enter second number: "))

x, y = swap(x, y)

print("After swapping:")
print("First number =", x)
print("Second number =", y)

GROUP N: ADDITIONAL IMPORTANT MATHEMATICAL PROGRAMS

Question 69. Calculate Power of a Number

Write a Python program using a user-defined function to input a base number and an exponent. Calculate the base raised to the given exponent. Return and display the result.

Answer:

def power(a, b):
    return a ** b

base = float(input("Enter base number: "))
exponent = int(input("Enter exponent: "))

result = power(base, exponent)
print("Result =", result)

Question 70. Remainder of Two Numbers

Write a Python program using a user-defined function to input two integers and calculate the remainder when the first number is divided by the second number. Return and display the result. Assume that the second number is not zero.

Answer:

def remainder(a, b):
    return a % b

x = int(input("Enter first number: "))
y = int(input("Enter second number: "))

result = remainder(x, y)
print("Remainder =", result)