Python Programming Series (Strings 3): An example with palindromes

preview_player
Показать описание
In this example we look at one of the common task beginner programmers are asked to do.
Рекомендации по теме
Комментарии
Автор

I got this one:
string = input('Enter anything: ')

print('PALINDROME') if string == string[::-1] else print('NOT PALINDROME')

philippecolin
Автор

Watching these and doing some exercises on the side has really helped me! Thank you for the effort you put into them.
Decided to give my own go at it by using a for loop - I'm new so don't go too hard on me xd

pal = 'applelppa'

for i in range(len(pal)):

first_half = pal[i]
last_half = pal[-1-i]
if first_half != last_half:
print('"{0}" is not a palindrome.'.format(pal))
break
else:
print('"{0}" is a palindrome.'.format(pal))
break

ram-pkec
Автор

I know this is years late but i am having trouble, this is what I have so far,


sentence=input()
sentence=sentence.lower()

#how to take out punctuation
sentence_without_pun="" #make an empty string first
for i in range(0, len(sentence)):
if (i==True): #how to check whether the letter is a lower case # you need to use [i]
sentence_without_pun+=1

print(sentence_list)

reverse_list.reverse()

if
print("it is a Palindrome")
else:
print("it is not a palindrome")

HghFrctose
Автор

--I'm new to python
pal = 'applelppa'

for i in range(0, len(pal) // 2):
if pal[i] != pal[-1-i]:
print("not a palindrome")
break
else:
print("a palindrome")

AnTran-ojkn
Автор

Pal=(input sentence)
pal=pal.lower()


if first_part==second_part:
print("This is a palindrome")
else:
print("This is not a palindrome")

siddheshpatil
welcome to shbcf.ru