Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2f872fd

Browse files
Palindrome done with some error handling
1 parent c7baa30 commit 2f872fd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎7-Palindrome.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 7 - Palindrome Test
2+
# Source: https://adriann.github.io/programming_problems.html
3+
# Write a function that tests whether a string is a palindrome.
4+
5+
print("Palindrome Test")
6+
7+
run = True
8+
9+
while run == True:
10+
word = input("Enter a word: ")
11+
print("Original: " + str(word))
12+
print("Reversed: " + str(word)[::-1])
13+
14+
# Reverse a string adapted from https://stackoverflow.com/questions/931092/reverse-a-string-in-python
15+
if str(word) == str(word)[::-1]:
16+
print("This is word is a palindrome.")
17+
print()
18+
19+
else:
20+
print("This is word is not a palindrome.")
21+
print()
22+
23+
again = input("Test another word? Y/N: ")
24+
25+
if again.lower() == "y":
26+
run = True
27+
elif again.lower() == "n":
28+
run = False
29+
else:
30+
again = input("Please enter Y/N: ")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /