1.
Add Two Numbers
Source code
a = 15
b = 12
c=a+b
print(c)
Output
27
2. Using user input
Source code
a = input("First number: ")
b = input("Second number: ")
res = float(a) + float(b)
print(res)
Output
First number: 4.1
Second number: 5.0
9.1
3. Maximum of two numbers
Source code
a = 10
b = 70
print(max(a, b))
Output
70
4. Using if-Else statement
Source code
a = 7
b = 3
if a > b:
print(a)
else:
print(b)
Output
7
5. Check Even or Odd
Source code
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Output
Enter a number: 4
Even
6. Simple Calculator
Source 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)
print("Quotient =", a / b)
Output
Enter first number: 20
Enter second number: 10
Sum = 30.0
Difference = 10.0
Product = 200.0
Quotient = 2.0
7. Area of rectangle
Source code
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
a=l*b
print("Area =", a)
Output
Enter length: 4
Enter breadth: 3
Area = 12.0