Posts

Showing posts with the label python tricks

Swapping Two Variables in Python

Image
  Swap two variables python example code: a = 5 b = 10 a, b = b, a print ( "a:"  , a) print ( "b:", b)

Calculate the Area of a Circle with PYTHON

Image
  Calculate the Area of a Circle import math radius = float ( input ( "Enter the radius of the circle: " )) area = math.pi * (radius ** 2 ) print ( "Area of the circle:" , area)

Simple Python Calculator

Image
Simple Python Calculator Code: num1 = int(input ("enter number") ) num2 = int(input ("enter number") ) action = str(input ("choose action: Add(a) Sub(s) Mult(m) Div(d) ->") ) print( "the result is", end="") if action == "a" : print(num1+num2) elif action == "s" : print(num1-num2) elif action == "m" : print(num1*num2) else: print(num1/num2)