20 Python Programs with Outputs
1. Sum, Difference, Product, and Division
Code:
a = float(input("Enter first number: ")) b = float(input("Enter second number: "))
print("Sum =", a + b) print("Difference =", a - b) print("Product =", a * b) if b !=
0: print("Division =", a / b) else: print("Division not possible (b = 0)")
Sample Output:
Enter first number: 12 Enter second number: 4 Sum = 16.0 Difference = 8.0 Product = 48.0 Division
= 3.0
2. Simple Interest
Code:
p = float(input("Enter Principal: ")) r = float(input("Enter Rate of Interest: ")) t
= float(input("Enter Time (in years): ")) si = (p * r * t) / 100 print("Simple
Interest =", si)
Sample Output:
Enter Principal: 1000 Enter Rate of Interest: 5 Enter Time (in years): 2 Simple Interest = 100.0