2

I'm new to python and programming in general and I wrote this code on Sublime Text, and I can't see the error in it.

print("Please enter a quote you would like to use: ")
quote = str(input())
print(quote.upper())
print()
print(quote.lower())
print()
print(quote.capitalise())
print()
print(quote.title())

Any help would be much appreciated.

Many thanks, Dan

1
  • 1
    Please give the version of your python or the whole traceback of the error. Commented Jul 12, 2013 at 9:16

2 Answers 2

7

Replace input() with raw_input():

print("Please enter a quote you would like to use: ")
quote = str(raw_input())

Or even:

quote = raw_input("Please enter a quote you would like to use: ")
Sign up to request clarification or add additional context in comments.

5 Comments

Unfortunately, the code in your answer does not work in the general case: either print() is a function and raw_input() does not exist (Python 3), or print is a statement (Python 2).
If you issue from __future__ import print_function or you pass it a single argument, yes (so I updated my previous comment because it does indeed work in that case). If you pass more than one argument, Python 2 will interpret them as a tuple, which is usually not what you want. See stackoverflow.com/q/12162629/464709.
I know that, thanks. But in this case it will still work as expected.
Thanks mishik, I used 'raw_input' and it worked..why is this?
In python 2 raw_input() just returns you a string, while input() tries to execute the input.
0

The reason isn't about whether to use raw_input() or input(). It's about taking an input in the first place. Sublime Text does not allow a user to give an input. Refer to here: Sublime Text 2 console input.

You can try SublimeREPL

3 Comments

I think OP means that Sublime does not show any syntax errors, not that it's a plugin for Sublime or something.
I have written other codes which have worked, however any code involving the user entering a string come up with a syntax error on line 1..so should I replace Sublime?
@user2575745 Yes, every time you use something to take an input (eg input() or raw_input(), an error will be raised because Sublime Text does not allow the user to give an input. Perhaps use another IDE, if you plan on doing this, yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.