Skip to content

Commit ba6bc2b

Browse files
Add files via upload
Added code to check palindrome string and armstrong number
1 parent 4a9319f commit ba6bc2b

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

palindrome_and_armstrong_check.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def palindrome(inp):
2+
if inp==inp[::-1]: #reverse the string and check
3+
print("Yes, {} is palindrome ".format(inp))
4+
else:
5+
print("No, {} is not palindrome ".format(inp))
6+
7+
8+
def armstrong(number):
9+
num=number
10+
length=len(str(num))
11+
total=0
12+
while num>0:
13+
temp=num%10
14+
total=total+(temp**length) #powering each digit with length of number and adding
15+
num=num//10
16+
if total==number:
17+
print("{} is Armstrong number".format(number) )
18+
else:
19+
print("{} is not an Armstrong number".format(number) )
20+
21+
palindrome('qwerewq')
22+
armstrong(407)

0 commit comments

Comments
 (0)