Sunday, September 28, 2025

Python Program Collection 07 - Divisiblle, odd, even, positive, negative or zero, greatest, smallest number

 


81. Divisible by 5

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

if n % 5 == 0:

    print(f"{n} is divisible by 5")

else:

    print(f"{n} is not divisible by 5")


82. Divisible by 3 and 7

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

if n % 3 == 0 and n % 7 == 0:

    print(f"{n} is completely divisible by 3 and 7")

else:

    print(f"{n} is not completely divisible by 3 and 7")


83. Positive, Negative or Zero

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

if n > 0:

    print(f"{n} is a positive number")

elif n < 0:

    print(f"{n} is a negative number")

else:

    print(f"{n} is zero")


84. Leap Year

y = int(input("Enter year: "))

if (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0):

    print(f"{y} is a leap year")

else:

    print(f"{y} is not a leap year")


85. Odd or Even

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

if n % 2 == 0:

    print(f"{n} is even")

else:

    print(f"{n} is odd")


86. Quotient and Remainder

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

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

 

if a > b:

    q = a // b

    r = a % b

else:

    q = b // a

    r = b % a

 

print(f"Quotient = {q}")

print(f"Remainder = {r}")


87. Positive or Negative

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

if n > 0:

    print(f"{n} is positive")

elif n < 0:

    print(f"{n} is negative")


88. Pass or Fail (>=40 pass)

m = int(input("Enter marks: "))

if m >= 40:

    print(f"You are PASS with {m} marks")

else:

    print(f"You are FAIL with {m} marks")


89. Eligible to Drive (>=16)

age = int(input("Enter your age: "))

if age >= 16:

    print(f"You are eligible to drive at age {age}")

else:

    print(f"You are not eligible to drive at age {age}")


90. Eligible to Vote (>=18)

age = int(input("Enter your age: "))

if age >= 18:

    print(f"You are eligible to vote at age {age}")

else:

    print(f"You are not eligible to vote at age {age}")

91. Enter 15 numbers, show divisible by 5

nums = []

for i in range(15):

    n = int(input(f"Enter number {i+1}: "))

    nums.append(n)

print("Numbers divisible by 5 are:")

for n in nums:

    if n % 5 == 0:

        print(f"{n} is divisible by 5")

92. Enter 15 numbers, show divisible by 5 and 7

nums = []

for i in range(15):

    n = int(input(f"Enter number {i+1}: "))

    nums.append(n)

 

print("Numbers divisible by 5 and 7 are:")

for n in nums:

    if n % 5 == 0 and n % 7 == 0:

        print(f"{n} is divisible by both 5 and 7")

93. Greater of Two Numbers

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

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

if a > b:

    print(f"{a} is greater")

else:

    print(f"{b} is greater")


94. Smaller of Two Numbers

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

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

 

if a < b:

    print(f"{a} is smaller")

else:

    print(f"{b} is smaller")

 

 

 

95. Greatest of Three Numbers

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

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

c = int(input("Enter third number: "))

if a > b and a > c:

    print(f"{a} is greatest")

elif b > a and b > c:

    print(f"{b} is greatest")

else:

    print(f"{c} is greatest")

96. Smallest of Three Numbers

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

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

c = int(input("Enter third number: "))

if a < b and a < c:

    print(f"{a} is smallest")

elif b < a and b < c:

    print(f"{b} is smallest")

else:

    print(f"{c} is smallest")

97. Middle of Three Numbers

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

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

c = int(input("Enter third number: "))

if (a > b and a < c) or (a < b and a > c):

    print(f"{a} is middle number")

elif (b > a and b < c) or (b < a and b > c):

    print(f"{b} is middle number")

else:

    print(f"{c} is middle number")

 

98. Greatest, Smallest and Middle of Three Numbers

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

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

c = int(input("Enter third number: "))

if a > b and a > c:

    greatest = a

elif b > a and b > c:

    greatest = b

else:

    greatest = c

if a < b and a < c:

    smallest = a

elif b < a and b < c:

    smallest = b

else:

    smallest = c

if (a > b and a < c) or (a < b and a > c):

    middle = a

elif (b > a and b < c) or (b < a and b > c):

    middle = b

else:

    middle = c

print(f"Greatest = {greatest}")

print(f"Middle = {middle}")

print(f"Smallest = {smallest}")


 

99. Greatest of 10 Numbers

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

for i in range(2, 11):

    g = int(input(f"Enter number {i}: "))

    if g > n:

        n = g

 

print(f"The greatest number is {n}")


100. Smallest of 10 Numbers

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

for i in range(2, 11):

    s = int(input(f"Enter number {i}: "))

    if s < n:

        n = s

 

print(f"The smallest number is {n}")


101. Greatest of 20 Numbers (Array Style)

nums = []

for i in range(20):

    n = int(input(f"Enter number {i+1}: "))

    nums.append(n)

 

greatest = nums[0]

for i in range(1, 20):

    if nums[i] > greatest:

        greatest = nums[i]

 

print(f"The greatest number is {greatest}")


102. Smallest of 20 Numbers (Array Style)

nums = []

for i in range(20):

    n = int(input(f"Enter number {i+1}: "))

    nums.append(n)

 

smallest = nums[0]

for i in range(1, 20):

    if nums[i] < smallest:

        smallest = nums[i]

 

print(f"The smallest number is {smallest}")


103. Greatest and Smallest of 20 Numbers (Array Style)

nums = []

for i in range(20):

    n = int(input(f"Enter number {i+1}: "))

    nums.append(n)

greatest = nums[0]

smallest = nums[0]

for i in range(1, 20):

    if nums[i] > greatest:

        greatest = nums[i]

    if nums[i] < smallest:

        smallest = nums[i]

print(f"Greatest number = {greatest}")

print(f"Smallest number = {smallest}")

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}")