So I have a code that counts the amount of words But I need it to count palindrome words times instead of one
For example, "Kids love doing gag. Gag is good."
We first enter how many words we will look for
We write 2
Then one by one we write these words
F.e first one is kids, and the second is gag.
As a result, our answer should be 5 (1 time kids, 2 times gag (But this is a palindrome, so it counts 4 times)
This is the code
text = input("Enter:")
text = text.lower()
quantity = int(input("How Many Words Do You Want Find: "))
word_counter = 0
word_for_find = []
for i in text:
if i == "." or i == "," or i == "!" or i == "?":
text = text.replace(i, "")
lst_text = text.split()
for i in range(quantity):
temp = input("Enter The Word: ")
temp = temp.lower()
word_for_find.append(temp)
for i in lst_text:
for j in word_for_find:
if j == i:
word_counter += 1
print(word_counter)
If I'm understanding you correctly you want to count palindromes twice. To check that I would create an if statement in the other if statement checking if it's the same in reverse:
if i == i[::-1]:
word_counter += 2
else:
word_counter += 1