Python Exercises (beginner) - Palindrome

preview_player
Показать описание
Another beginner Python exercise.
Determine if a string is a palindrome or not.

Leave comments below.

Just created a facebook page:

Here is my reddit account for sharing links:

(I highly appreciate shares)

Here is my twitter account for programming:

Here is my github account:

Рекомендации по теме
Комментарии
Автор

This is my first ever exercise that I was able to do with my own knowledge thank you for that!

mj-ptty
Автор

These exercises are fun and challenging, but I always know that my "solution", while functional, will be way too complex and won't take advantage of any advanced short cuts. This was no exception.

palindrome = True
test = input ("Enter a word and I'll tell you if it's a palindrome: ")
length = len(test)

for i in range (length // 2): #I only have to check through half of the word
if test [i] != test [(length-1)-i]:
palindrome =False
break
else:
continue

if palindrome == True:
print (f"{test} just might be a palindrome")
else:
print ("I don't think that's a palindrome: ")

pauljacobus
Автор

def is_pal(string):
length = len(string)
counter = 0
for i in range(0, length):

counter += 1
if counter == length:
print(f"The string {string} is a palindrome.")
else: print(f"The string {string} is NOT a palindrome.")

ancientgear