Python program to calculate the area of a circle.

In this python basic program, we will calculate the area of a circle.

Steps to solve the program
  1. Take the radius of the circle as input through the user.
  2. Calculate the area of a circle using the following formula: Pi*r*r, where pi is equal to 3.14 and r is the radius of the circle.
  3. Print the output.
				
					radius = int(input("Enter radius of circle: "))
area = 3.14*radius*radius

print("Area of circle: ",area)
				
			

Output :

				
					Enter radius of circle: 4
Area of circle:  50.24
				
			

calculate the area of the square.

calculate the area of a cube.

Python program to calculate the area of the square.

In this python basic program, we will calculate the area of the square.
Formula: area = side^2

Steps to solve the program
  1. Take a side of a square as input through the user.
  2. To calculate the area of the square use the following formula: side^2.
  3. Print the output.
				
					side = int(input("Enter the side of a square: "))
print("Area of sqaure: ",side**2)
				
			

Output :

				
					Enter the side of a square: 10
Area of sqaure:  100
				
			

solve the given math formula. Formula : (a – b)3 = a3 – 3a2b + 3ab2 – b3

calculate the area of a circle.

Python program to solve the given math formula.

In this python basic program, we will solve the given math formula.
Formula : (a – b)3 = a3 – 3a2b + 3ab2 – b3

Steps to solve the program
  1. Take two variables as input and assign value to them.
  2. Using logic solve the given math formula.
  3. Formula : (a – b)3 = a3 – 3a2b + 3ab2 – b3
  4. Print the output.
				
					a = 3
b = 2
result = a**3-3*a**2*b+3*a*b**2+b**3

print("(a-b)^3: ",result)
				
			

Output :

				
					(a-b)^3:  17
				
			

solve the given math formula. Formula : (a + b)3 = a3 + 3ab(a+b) + b3 

calculate the area of the square.

Python program to solve the given math formula.

In this python basic program, we will solve the given math formula.
Formula : (a + b)3 = a3 + 3ab(a+b) + b3 

Steps to solve the program
  1. Take two variables as input and assign value to them.
  2. Using logic solve the given math formula.
  3. Formula : (a + b)3 = a3 + 3ab(a+b) + b3 
  4. Print the output.
				
					a = 3
b = 2
result = a**3+3*a*b*(a+b)+b**3

print("(a+b)^3: ",result)
				
			

Output :

				
					(a+b)^3:  125
				
			

solve the given math formula. Formula : a2 – b2 = (a-b)(a+b)

solve the given math formula. Formula : (a – b)3 = a3 – 3a2b + 3ab2 – b3

Python program to solve the given math formula.

In this python basic program, we will solve the given math formula.
Formula : a2 – b2 = (a-b)(a+b)

Steps to solve the program
  1. Take two variables as input and assign value to them.
  2. Using logic solve the given math formula.
  3. Formula : a2 – b2 = (a-b)(a+b)
  4. Print the output.
				
					a = 3
b = 2
result = (a+b)*(a-b)

print("(a^2-b^2): ",result)
				
			

Output :

				
					(a^2-b^2):  5
				
			

solve the given math formula. Formula : (a – b)2 = a^2 + b^2 – 2ab

solve the given math formula. Formula : (a + b)3 = a3 + 3ab(a+b) + b3 

Python program to solve the given math formula.

In this python basic program, we will solve the given math formula.
Formula : (a – b)2 = a^2 + b^2 – 2ab

Steps to solve the program
  1. Take two variables as input and assign value to them.
  2. Using logic solve the given math formula.
  3. Formula : (a – b)2 = a^2 + b^2 – 2ab
  4. Print the output.
				
					a = 2
b = 3
result = a**2-2*a*b+b**2

print("(a-b)^2: ",result)
				
			

Output :

				
					(a-b)^2:  1
				
			

solve the given math formula.
Formula : (a + b)2 = a^2 + b^2 + 2ab

solve the given math formula. Formula : a2 – b2 = (a-b)(a+b)

Python program to solve the given math formula.

In this python basic program, we will solve the given math formula.
Formula : (a + b)2 = a^2 + b^2 + 2ab

Steps to solve the program
  1. Take two variables as input and assign value to them.
  2. Using logic solve the given math formula.
  3. Formula : (a + b)2 = a^2 + b^2 + 2ab
  4. Print the output.
				
					a = 2
b = 3
result = a**2+2*a*b+b**2

print("(a+b)^2: ",result)
				
			

Output :

				
					(a+b)^2:  25
				
			

Solve this Pythagorous theorem.

solve the given math formula.
Formula : (a – b)2 = a^2 + b^2 – 2ab

Program to interchange values between variables.

In this Python basic program, we will interchange values between variables.

Steps to solve the program

  1. Take two variables as input and assign value to them.
  2. Interchange their values using “, = “.
  3. Print the variables after interchanging the values.

Program:

a = 50
b = 70
a, b = b, a

print("value of a :", a)
print("value of b :", b)

Output:

value of a : 70
value of b : 50


Print the square and cube of a given number.

In this basic Python program, we will print the square and cube of a given number using the ** method.

Steps to solve the program

  1. Take a number as input.
  2. Print the square and cube using the ** (power) method.
  3. To print the square use  **2 and for the cube use **3.
  4. Print the output.

Program :

n = 9

print("Square of number :", n**2)

print("Cube of number :", n**3)

Output :

Square of number: 81
Cube of number: 729



Program to get the median of given numbers.

This Python basic program will get the median of given numbers. 

Steps to solve the program

  1. Take a list as input.
  2. Sort the given list using sort().
  3. Get the length of the list.
  4. If the length of the list is odd, then use the formula
    (n+1)/2 to find the median of the given list.
  5. If the length of the list is odd, then use the formula.
    Use the formula (n+1)/2 to find the median of the given list, where n is the length of the list.
  6. If the length of the list is even, then use the formula.
    Use the formula ((n/2 – 1) + n/2)/2 to find the median of the given list, where n is the length of the list
  7. Print the output.


Program:

# example list of values
values = [10, 20, 30, 40, 50]

# sort the list
values.sort()

# get length of the list
n = len(values)

if n % 2 == 1:
    median_value = values[n // 2]
else:
    median_value = (values[n // 2 - 1] + values[n // 2]) / 2

print(f"The median is: {median_value}")

Output:

The median is: 30