Python Code 1.Check whether a number is palindrome or not. 2.Search for a number in a list

  • Check whether a given number is Palindrome or Not

Source Code:
num=int(input("Enter the number: "))
s_num=num
r_num=0

while(num!=0):
    rem=num%10
    r_num=r_num*10+rem
    num=num//10

if(s_num==r_num):
    print("{} is a Palindrome Number.".format(s_num))
else:
    print("{} is not a Palindrome Number.".format(s_num))

Output:
Enter the number: 23332
23332 is a Palindrome Number.

Enter the number: 234
234 is not a Palindrome Number.

  • Search for a number in a list

Source Code:
num_list=[23,43,84,53,39]

find_num=int(input("Enter the number to be search: "))

pos=None

if(find_num in num_list):
    pos=num_list.index(find_num)
    print("Number is found at index[{}]".format(pos))
    # print("Number is found at index %d." %(ind))
else:
    print("Number is not found. Pls...Try with another number.")
Output:
Enter the number to be search: 53
Number is found at index[3]

Enter the number to be search: 45
Number is not found. Pls...Try with another number.

For any query, please comment below.
SUBSCRIBE



Post a Comment

0 Comments