jk23541
jk23541

Reputation: 57

How to incorporate quotation marks into a user input?

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.

Upvotes: 2

Views: 983

Answers (2)

AdrienW
AdrienW

Reputation: 3452

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()

Upvotes: 1

DeepSpace
DeepSpace

Reputation: 81594

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

Upvotes: 1

Related Questions