Program to check given number is palindrome or not.

In this python basic program we will check whether the given number is palindrome or not.

Steps to solve the program
  1. Take a number as input through the user and create a variable rev and assign its value equal to 0.
  2. Use a while loop to find the reverse of a number.
  3. While num is greater than 0 divide the number by 10 using % to find the remainder.
  4. Multiply the rev by 10 and add the remainder to it.
  5. Now divide the number by 10 using //.
  6. If the reversed number is equal to the input number then it is a palindrome.
				
					n = num = int(input("Enter a number: "))
rev = 0

while n>0:
    rem = n%10
    rev = rev*10+rem
    n = n//10
    
if num == rev:
    print("Given number is a palindrome number")
else:
    print("Given number is not a palindrome number")
				
			

Output :

				
					Enter a number: 121
Given number is a palindrome number
				
			

Fibonacci series between 0 to 50.

calculate compound interest.

Program to get the Fibonacci series between 0 to 50.

In this python basic program, we will get the Fibonacci series between 0 to 50 numbers.

Steps to solve the program
  1. Create two variables and assign their values equal to 0 and 1 respectively.
  2. Create another variable count and assign its value equal to 0.
  3. While the count variable is less than 50 print the num1.
  4. Add num1 and num2 and assign their addition to the n2 variable.
  5. Change the value of num1 with num2 and num2 with n2.
  6. Add 1 to the count variable.
  7. Print the Fibonacci series.
				
					num1 = 0
num2 = 1
count = 0

print("Sequence is: ",end=" ")
while count<50:
    print(num1,end=" ")
    n2 = num1+num2
    num1 = num2
    num2 = n2
    count += 1
				
			

Output :

				
					Sequence is:  0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 
987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 
196418 317811 514229 832040 1346269 2178309 3524578 5702887
9227465 14930352 24157817 39088169 63245986 102334155 165580141 
267914296 433494437 701408733 1134903170 1836311903 2971215073 
4807526976 7778742049 
				
			

reverse a given number.

check given number is palindrome or not.

Python program to reverse a given number

In this python basic program, we will reverse a given number without using some logic.

Steps to solve the program
  1. Take a number as input through the user.
  2. Convert the number into a string by using str() as we cannot use indexing on integers.
  3. Reverse the string i.e. number using indexing.
  4. Print the output.
				
					num = int(input("Enter a number: "))

reverse = str(num)

print("Reverse: ",reverse[::-1])
				
			

Output :

				
					Enter a number: 236
Reverse:  632
				
			

get the factorial of the given number

get the Fibonacci series between 0 to 50.

Program to get the factorial of the given number.

In this python basic program, we will get the factorial of the given number using while loop.

Steps to solve the program
  1. Take a number as input through the user and create a variable named fact and assign its value equal to 1.
  2. While the input number is greater than 0 multiply the fact by the number.
  3. After each multiplication subtract 1 from the input number.
  4. Print the output,
				
					num = n = int(input("Enter a number: "))
fact = 1
while n > 0:
    fact *= n
    n -= 1
print(f"Factorial of {num}: {fact}")
				
			

Output :

				
					Enter a number: 5
Factorial of 5: 120
				
			


Previous

calculate days between 2 dates.


Next

reverse a given number.

Python program to calculate days between 2 dates

In this python basic program,we will calculate days between 2 dates using datetime library.

Steps to solve the program
  1. From datetime import date().
  2. Pass the date() to the given dates.
  3. Subtract date_2 from date_1 and calculate only days using .days
  4. Print the output.
				
					from datetime import date 

date_1 = date(2023, 1, 5) 
date_2 = date(2023, 1, 22) 

result = (date_2 - date_1).days  
print ("Number of Days between the given Dates are: ", result, "days")  
				
			

Output :

				
					Number of Days between the given Dates are:  17 days
				
			

print the current date in the given format

get the factorial of the given number.

Python program to print the current date

In this python basic program, we will print the current date in the format given int the question.

Steps to solve the program
  1. Import datetime.
  2. Using datetime get the current date with the help of datetime.datetime.now().
  3. Print the current date in the required format using date.strftime().
				
					import datetime 
date = datetime.datetime.now()  

print (date.strftime (" %Y %b %d "))
				
			

Output :

				
					2023 Jan 28 
				
			

calculate simple interest.

Calculate days between 2 dates.

Python program to calculate simple interests.

In this python basic program, we will calculate simple interests using the formula P+(P/r)*t.

Steps to solve the program
  1. Take the principal amount, rate of interest, and number of years as input.
  2. Calculate the simple interest using the formula P+(P/r)*t, where P is the principal amount, r is the rate of interest, t is the number of years.
  3. Print the output.
				
					p = 1000
r = 10
t = 2

amount = p+(p/r)*t

print("Amount payable: ",amount)
				
			

Output :

				
					Amount payable:  1200.0
				
			

check whether the given number is an Armstrong number or not.

print the current date in the given format

Check whether the given number is an Armstrong number.

In this python basic program, we will check whether the given number is an Armstrong number or not.

Steps to solve the program
  1. Take a number as input through the user.
  2. See the given example to understand what is an Armstrong number.
  3. Create a variable and assign its value equal to 0.
  4. While the number is greater than 0 divide the number by 10 using % and add the remainder raised to 3 to the variable that we have created.
  5. Now divide the number by 10 using //.
  6. If the value of the variable is equal to the input number then it is an Armstrong number.
  7. Print the output
				
					num = a = 153
rev = 0

while a>0:
    rem = a%10
    rev = rev +rem**3
    a= a//10
    
if rev == num:
    print("It is a armstrong number")
else:
    print("It is not a armstrong number")
				
			

Output :

				
					It is a palindrome number
				
			

calculate the area of the cylinder.

calculate simple interest.

Python program to calculate the area of the cylinder.

In this python basic program, we will calculate the area of the cylinder using the formula 2*PI*r*h + 2*PI*r*r.

Steps to solve the program
  1. Take the radius and height of the cylinder as input through the user.
  2. Calculate the area of the cylinder using the formula: 2*PI*r*h + 2*PI*r*r, where h is the height and r is the radius of the cylinder.
  3. Print the output.
				
					r = int(input("Enter radius of cylinder: "))
h = int(input("Enter height of cylinder: "))
area = 2*3.14*r*h+2*3.14*r*r

print("Area of cylinder: ",area)
				
			

Output :

				
					Enter radius of cylinder: 4
Enter height of cylinder: 5
Area of cylinder:  226.08
				
			

calculate the area of a cube.

check whether the given number is an Armstrong number or not.

Python program to calculate the area of a cube.

In this python basic program, we will calculate the area of a cube. We will use the the formula: 6*side*side,

Steps to solve the program
  1. Take the side of a cube as input through the user.
  2. Calculate the area of the cube using the formula: 6*side*side.
  3. Print the output.
				
					side = int(input("Enter side of a cube: "))
area = 6*side*side

print("Area of cube: ",area)
				
			

Output :

				
					Enter side of a cube: 6
Area of cube:  216
				
			

calculate the area of a circle.

calculate the area of the cylinder.