2
def palindrome(s):
    s=input ("Enter a phrase (**use quotation marks for words**): ")
    s.lower()
    return s[::-1]==s

palindrome(s)

This is my code. How do I change it so I can take out the bolded section? I use python 2 and it won't accept string inputs without the quotation marks.

irowe
  • 462
  • 10
  • 15
jk23541
  • 57
  • 9
  • 2
    Possible duplicate of [Python - Using quotation marks inside quotation marks](http://stackoverflow.com/questions/9050355/python-using-quotation-marks-inside-quotation-marks) – Eli Korvigo Aug 01 '16 at 07:16
  • 2
    Are you sure you want to use `input()`? Try using `raw_input()` instead. – cdarke Aug 01 '16 at 07:16

2 Answers2

1

Use raw_input instead of input. In Python 2 input tries to evaluate the user's input, so letters are evaluated as variables.

DeepSpace
  • 72,713
  • 11
  • 96
  • 140
1

A raw_input will do the job. This question about input differences in Python 2 and 3 might help you.

Besides, I think the parameter s is not necessary. And s.lower() alone does not change the value of s.

def palindrome():
    s = raw_input("Enter a phrase : ")
    s = s.lower()
    return s[::-1] == s

palindrome()
Graham
  • 7,035
  • 17
  • 57
  • 82
AdrienW
  • 2,441
  • 4
  • 22
  • 51
  • Another thing, so the raw_input makes it considered like a string? And also I used the s.lower because when I tried to run "Eat Tae", it wouldsay it wasn't a palindrome. How do I solve this? – jk23541 Aug 01 '16 at 07:32
  • Yes, unlike `input`, in Python 2 `raw_input` does not try to evaluate what you write, and takes it as a string. So you don't need quotes and it works. For `lower`, just calling `s.lower()` returns a string that corresponds to `s` with all lowercase characters. But it is not automatically stored in `s`. Therefore you have to do `s = s.lower()` – AdrienW Aug 01 '16 at 07:56