Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #save this file as "palindrome.py"
  2. #will be used as  library of functions
  3.  
  4. #Returns true if sentence is a palindrome
  5. def palindrome(sentence):
  6.     count = 0
  7.     sentence = sentence.lower()
  8.     for i in range(len(sentence)):
  9.         if sentence[i] == sentence[-(i+1)]:
  10.             count = count + 1
  11.     return count == len(sentence)
  12.  
  13. #takes a string as an input,
  14. #removes punctuation and spaces and puts all words into a single word
  15. def one_word(sentence):
  16.     punctuation = [",", "?", ".", " "]
  17.    
  18.     for i in range(len(punctuation)):
  19.         sentence = sentence.replace(punctuation[i], " ")
  20.  
  21.     sentence = sentence.split(" ")
  22.     new_sentence = ""
  23.  
  24.     for i in range(len(sentence)):
  25.         new_sentence = new_sentence + sentence[i]
  26.  
  27.     return new_sentence
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement