Sunday, September 28, 2025

Python Program Collection 06 - calculate distance, potential energy

 


66.  Calculate distance.[s=ut+1/2(at2)]

u = float(input("Enter initial velocity (u): "))

t = float(input("Enter time (t): "))

a = float(input("Enter acceleration (a): "))

s = (u * t) + (0.5 * a * (t ** 2))

print(f"Distance travelled is {s}")

 

67.   Calculate potential energy of body. [pe=mgh where g=9.8]

m = float(input("Enter mass of the body (in kg): "))

h = float(input("Enter height of the body (in meters): "))

g = 9.8

pe = m * g * h

 

print(f"Potential energy of body with mass {m} kg at height {h} m is {pe} Joules")

 

68. Ask quantity of pen, copy and pencil and their rate and find out the total amount.

q_pen = int(input("Enter quantity of pens: "))

q_copy = int(input("Enter quantity of copies: "))

q_pencil = int(input("Enter quantity of pencils: "))

r_pen = float(input("Enter rate of one pen: "))

r_copy = float(input("Enter rate of one copy: "))

r_pencil = float(input("Enter rate of one pencil: "))

total = (q_pen * r_pen) + (q_copy * r_copy) + (q_pencil * r_pencil)

print(f"Total amount = {total}")

 

69. Input n number and print the sum of first n natural numbers.

n = int(input("Enter a number (n): "))

sum_n = n * (n + 1) // 2  

print(f"Sum of first {n} natural numbers is {sum_n}")

 

70. Input n number and print the sum square of first n natural numbers.

n = int(input("Enter a number (n): "))

sum_squares = (n * (n + 1) * (2 * n + 1)) // 6

print(f"Sum of squares of first {n} natural numbers is {sum_squares}")


71. Input distance in kilometer and convert into miles.

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

miles = km * 0.621371

print(f"{km} kilometers is equal to {miles} miles")

 

72. Input value in kilogram and convert into grams.

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

grams = kg * 1000

print(f"{kg} kilograms is equal to {grams} grams")

 

 

 

 

73. Input value in meter and convert into inch.

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

inch = meter * 39.3701

print(f"{meter} meters is equal to {inch} inches")

 

75. Input sales amount and rate of commission then calculate commission and return nt sales. [ns=sa-c)

sa = float(input("Enter sales amount: "))

rate = float(input("Enter commission rate (%): "))

commission = (sa * rate) / 100

ns = sa - commission

print(f"Sales Amount = {sa}")

print(f"Commission = {commission}")

print(f"Net Sales = {ns}")

 

76. Input number as paise and convert into rupees only.

paise = int(input("Enter amount in paise: "))

rupees = paise / 100

print(f"{paise} paise is equal to {rupees} rupees")

 

 

77. Find cost of painting the four walls of a room.

length = float(input("Enter length of the room: "))

breadth = float(input("Enter breadth of the room: "))

height = float(input("Enter height of the room: "))

rate = float(input("Enter cost of painting per square unit: "))

area_walls = 2 * (length + breadth) * height

cost = area_walls * rate

print(f"Area of four walls = {area_walls}")

print(f"Total cost of painting = {cost}")

 

78. Solve a quadratic equation ax2+bx+c=0 on the basis of the coefficient values a, b, and c.

 

 

a = float(input("Enter coefficient a: "))

b = float(input("Enter coefficient b: "))

c = float(input("Enter coefficient c: "))

D = (b ** 2) - (4 * a * c)   # discriminant

if D > 0:

    root1 = (-b + (D ** 0.5)) / (2 * a)

    root2 = (-b - (D ** 0.5)) / (2 * a)

    print(f"Roots are real and distinct: {root1}, {root2}")

elif D == 0:

    root = -b / (2 * a)

    print(f"Roots are real and equal: {root}, {root}")

else:

    print("No real roots (imaginary roots).")

 

79. Display sum of half of any two given numbers.

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

b = float(input("Enter second number: "))

result = (a / 2) + (b / 2)

print(f"Sum of half of {a} and {b} is {result}")

 

 

80. Calculate total saving of a man if he earns rs. 10,000 per month and spends 20% on food, 15% on children’s education, 10% on entertainment and 20% on rent.

income = 10000

food = (20 / 100) * income

education = (15 / 100) * income

entertainment = (10 / 100) * income

rent = (20 / 100) * income

total_expense = food + education + entertainment + rent

saving = income - total_expense

 

print(f"Monthly Income = Rs. {income}")

print(f"Total Expenses = Rs. {total_expense}")

print(f"Total Saving = Rs. {saving}")

 

No comments:

Post a Comment