Python program to check for the anagram.

In this python basi program, we will check for the anagram i.e. rearrangement of the letters of a word to another word, using all the original letters once.

Steps to solve the program
  1. Take a word as input and create a variable named combination and assign its value equal to 0.
  2. We have to find the number of words that can be formed by using letters available in the given word.
  3. Create a variable and assign it a value equal to the letters available in the input word.
  4. While the value of that variable is greater than 0 add 1 to combination variable and subtract 1 from the above variable.
  5. Print the output.
				
					word = input("Enter a word: ")
combination = 0
characters = len(word)

while characters>0:
    combination += characters
    characters -= 1

print("Total combinations without repetaation: ",combination)
				
			

Output :

				
					Enter a word: python
Total combinations without repetaation:  21
				
			

check leap year.

generate random numbers.

Python program to check year is a leap year.

In this python basic program, we will check whether the given year is a leap year or not.

Steps to solve the program
  1. Take a year as input through the user.
  2. Use the following condition to check whether the given year is a leap year or not – (year%400 == 0 or year%100 != 0) and year%4 == 0.
  3. Print the respective output.
				
					year = int(input("Enter a year: "))

if (year%400 == 0 or year%100 != 0) and year%4 == 0:
    print(f"{year} is a leap year")
else:
    print(f"{year} is not a leap year")
				
			

Output :

				
					Enter a year: 1700
1700 is not a leap year
				
			

check the prime number.

check for the anagram.

Python program to check the prime number.

In this python basic program, we will check the whether the given number is a prime number.

Steps to solve the program
  1. Take a number as input through the user and create a count variable and assign its value equal to 0.
  2. Use for loop with the range function to check whether a number is a prime number or not.
  3. If a number divides the input number then add 1 to the count variable.
  4. If a number is divisible by 1 and by itself then it is a prime number.
  5. Print the output.
				
					num = int(input("Enter a number: "))
count = 0

for i in range(1,num+1):
    if num%i == 0:
        count += 1
        
if count == 2:
    print(f"{num} is a prime number")
else:
    print(f"{num} is not a prime number")
				
			

Output :

				
					Enter a number: 53
53 is a prime number
				
			

calculate compound interest.

check leap year.

Python program to calculate compound interest.

In this python basic program, we will calculate compound interest using formula p*((1+r/100)**n).

Steps to solve the program
  1. Take the principal amount, rate of interest, and a number of years as input through the user.
  2. Calculate the compound interest using the formula p((1+r/100)**n).
  3. Print the output.
				
					p = int(input("Enter principle amount: "))
r = float(input("Enter interest rate: "))
n = int(input("Enter number of years: "))

amount = p*((1+r/100)**n)

print("Compoud interest: ",amount)
				
			

Output :

				
					Enter principle amount: 10000
Enter interest rate: 10
Enter number of years: 2
Compoud interest:  12100.000000000002
				
			

check given number is palindrome or not.

check the prime number.

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.