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

DCragg
  • 31
  • 1
  • 1
  • 4

2 Answers2

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: ")
mishik
  • 9,973
  • 9
  • 45
  • 67
  • 1
    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). – Frédéric Hamidi Jul 12 '13 at 09:16
  • 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 http://stackoverflow.com/q/12162629/464709. – Frédéric Hamidi Jul 12 '13 at 09:19
  • I know that, thanks. But in this case it will still work as expected. – mishik Jul 12 '13 at 09:21
  • Thanks mishik, I used 'raw_input' and it worked..why is this? – DCragg Jul 12 '13 at 09:28
  • In python 2 raw_input() just returns you a string, while input() tries to execute the input. – mishik Jul 12 '13 at 09:31
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

Community
  • 1
  • 1
TerryA
  • 58,805
  • 11
  • 114
  • 143
  • I think OP means that Sublime does not show any syntax errors, not that it's a plugin for Sublime or something. – mishik Jul 12 '13 at 09:17
  • 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? – DCragg Jul 12 '13 at 09:23
  • @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 – TerryA Jul 12 '13 at 09:24