Python Code Examples
Calculator In Python
This page contains examples of basic concepts of Python programming like loops, functions, native datatypes and so on. This page shows source code and examples in python
def add(x, y): return x + y def subtract(x, y): return x - y def multiply(x, y): return x * y def divide(x, y): return x / y print("Select Operation") print("1.Add") print("2.Subtract") print("3.Multiply") print("4.Divide") while True: choice = input("Enter Your Choice(1/2/3/4):") if choice in ('1', '2', '3', '4'): num1 = float(input("Enter First Number:")) num2 = float(input("Enter Second Number:")) if choice == '1': res = num1+num2 print("Ans:",res) elif choice == '2': res = num1-num2 print("Ans:",res) elif choice == '3': res = num1*num2 print("This is your number:",res) elif choice == '4': res = num1/num2 print("This is your number:",res)
Multiplication Table In Python
print("Multiplication Table") num = int(input("Choose your number:")) for i in range(1, 21): print(num, 'x', i, '=', num*i)
Reverse Count In Python
print("Reverse count") num = int(input("Choose your number:")) for i in range(1, 101): print(num, '-', i, '=', num-i)