Skip to main content

S.Y.I.T Sem 3 Python Practical | Python| Python practical 1e| Write a function to check the input value is Armstrong and also write the function for Palindrome.| python for beginner

 Hello reader's

In this post you are going to see that how you can check that the giver number Armstrong or not and Palindrome or not. For understanding this you must know about Armstrong number and Palindrome number. Let's what is Armstrong number and Palindrome number.





What is Armstrong number?

The Armstrong number definition is the number in any given number base, which forms the total of the same number, when each of its digits is raised to the power of the number of digits in the number. 

A number is called an Armstrong number when the number ABCD = A^n+ B^n+ C^n+ D^n

Where n is the total number that is n=ABCD.

Let's understand it with a example:- 

Take a number 1634. Now we have to check that the number 1634 is Armstrong or not. 

According to formula  ABCD = A^n+ B^n+ C^n+ D^n

Where n is the total number that is n=ABCD

1634 = 1^4 + 6^4 + 3^4 + 4^4

1634 = 1 + 1296 + 81 + 256

1634 = 1634 , which means that the number 1634 is a Armstrong number.

You can also try with some other numbers like - 153, 371, 9474 etc.



Now the next topic is Palindrome number. Do you know what is Palindrome number? 

What is palindrome number ?

A number is called Palindrome when the reverse of the number is equal to the original number.

Lets understand it with a example :-

Lets suppose number 1234. Now we have to check that the number 1234 is Palindrome or not.

according to definition , number must be equal to reverse of it, therefore the number 

1234 = Reverse of the nuber

1234 = 4321 (which is not equal)

So the given number 1234 is not a palindrome number.

Let's one more example , The number is 2002 

2002 = Reverse of the number

2002=2002 

So the above given numbers 2002 are called as palindrome number. 

Palindrome number
I hope you people have understand that what is Armstrong number and What is Palindrome number.







Code :- 
def armstrong(num):
    sum=0
    temp = num
    while temp>0:
        digit = temp%10
        sum += digit** 3
        temp //=10
    if num ==sum:
        print(num,"is an Armstrong number")
    else:
        print(num,"is not an armstrong number")



def palindrome(num):
    n = num
    rev = 0
    while num !=0:
        rev = rev*10
        rev = rev + int(num%10)
        num = int(num /10)
    if n== rev:
        print(n,"is a palindrome number")
    else:
        print(n,"is not a palindrome number")


num = int(input("Enter a number to check it is Armstrong or not: "))
armstrong(num)
num = int(input("Enter a number to check it is Palindrome or not: "))
palindrome(num)


Comments

Popular posts from this blog

Android 13 features| Android 13 updates| Material You design| language Customizable| Android themes Privacy and security controls in Android 13| App Hibernation in Android 13| Adaptive Charging in Android 13| Android 13 release date| Android Beta Program| Latest Android version

 Android 13: What's New and Exciting? Android 13, codenamed Tiramisu, is the latest version of Google's mobile operating system that is expected to launch in late 2023. Android 13 promises to bring a host of new features and improvements to enhance the user experience, security, and performance of Android devices. In this blog post, we will take a look at some of the most anticipated features of Android 13 and how they will benefit users and developers alike. One of the biggest changes in Android 13 is the introduction of Material You, a new design language that adapts to the user's preferences, mood, and context. Material You allows users to customize their device's theme, colors, fonts, icons, and shapes according to their personal style and taste. Material You also changes dynamically based on the time of day, the wallpaper, the app, and the device mode. For example, if the user switches to dark mode, the system will automatically adjust the colors and brightness to ...

Define a procedure histogram() that takes a list of integers and prints a histogram to the screen| Histogram procedure| printing histogram| Python histogram function| Python programming

  How to Visualize Data with Python: Defining a Procedure Histogram() When it comes to analyzing data, visualization is key. Being able to see the patterns and trends in your data can make all the difference in understanding it. Luckily, Python has a built-in function for creating histograms, which is a powerful tool for visualizing data. In this blog post, we'll define a procedure called histogram() that takes a list of integers and prints a histogram to the screen. Before we get into the nitty-gritty of the code, let's briefly discuss what a histogram is and why it's useful. A histogram is a graphical representation of a frequency distribution, which is essentially a way to show how often certain values occur in a dataset. It's a great way to get a quick sense of the shape of your data, including its range, distribution, and outliers. Now, let's dive into the code. Here's how you can define a procedure histogram() in Python: def histogram(int_list):     for i ...

DALL-E AI, AI-generated images, GPT-3, OpenAI, artificial intelligence, natural language processing, deep learning, neural networks, image synthesis, image recognition, visual content creation.

 DALL.E is an AI system that can create images from text descriptions, using a large neural network trained on a dataset of text-image pairs. It was introduced by OpenAI in January 2021, and has since been improved with DALL.E 2, which generates more realistic and accurate images with higher resolution. In this blog post, I will explain how DALL.E works and show some examples of its amazing capabilities. DALL.E is based on GPT-3, a transformer language model that can generate text for a wide range of tasks. DALL.E extends GPT-3 by adding image tokens to its vocabulary, allowing it to generate both text and images in a single stream of data. DALL.E receives both the text and the image as input, and is trained to generate all of the tokens, one after another, using maximum likelihood. To represent images, DALL.E uses a discrete variational autoencoder (VAE) that compresses each image to a 32x32 grid of discrete latent codes. Each code corresponds to one of 8192 possible image tokens....