Knowee
Questions
Features
Study Tools

Susi loves playing with numbers and exploring their unique properties. One day, she learned about palindromic numbers and decided to write a program to check if a given number is a palindrome or not. Can you help her accomplish this task using a while loop?

Question

Susi loves playing with numbers and exploring their unique properties. One day, she learned about palindromic numbers and decided to write a program to check if a given number is a palindrome or not. Can you help her accomplish this task using a while loop?

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Python program that uses a while loop to check if a number is a palindrome:

def is_palindrome(num):
    temp = num
    reverse_num = 0

    while num > 0:
        digit = num % 10
        reverse_num = reverse_num * 10 + digit
        num = num // 10

    if temp == reverse_num:
        return True
    else:
        return False

# Test the function
print(is_palindrome(12321))  # True
print(is_palindrome(12345))  # False

In this program, we first store the input number in a temporary variable. Then we use a while loop to reverse the number. In each iteration of the loop, we take the last digit of the number (using num % 10), add it to reverse_num (after shifting reverse_num one place to the left), and remove the last digit from num (using num // 10). Finally, we check if the original number and the reversed number are the same. If they are, the number is a palindrome; otherwise, it's not.

This problem has been solved

Similar Questions

Problem StatementSusi loves playing with numbers and exploring their unique properties. One day, she learned about palindromic numbers and decided to write a program to check if a given number is a palindrome or not. Can you help her accomplish this task using a while loop?Note: palindrome is a number that is the same when reversed. For example, 121, 1331, and 45654 are palindromic numbers.Input format :The input consists of a single integer, n, where n is the number that Susi wants to check for palindromic properties.Output format :The output displays one of the following messages:"Palindrome" if n is a palindrome."Not a Palindrome" if n is not a palindrome.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:11 ≤ n ≤ 106Sample test cases :Input 1 :2552Output 1 :PalindromeInput 2 :1234Output 2 :Not a PalindromeInput 3 :11Output 3 :PalindromeInput 4 :1000000Output 4 :Not a Palindrome

Write a programme to check whether given input is palindrome or notConstraintsABC != PalindromeMAM == Palindrome123 != Palindrome151 == Palindrome

Write a C++ program to check if a given number is a palindrome. A palindrome is a number that remains the same when its digits are reversed.

Write a program in java to accept a number and chech whether it is a palindrome number or not. Do the program without using modulus operator and String.

Check Palindrome NumberWrite a program to check if the given number is a palindrome number.A palindrome number is a number that is the same after reverse. For example, 545, is the palindrome numbers

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.