-1

I am a complete noob in python and in programming, so I'm sure this question it may irritate some, so I am reading this book which has this example which it does not run with out raw_input

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Filename: continue.py
#!/usr/bin/python
# Filename: break.py
while True:
s = (raw_input('Enter something : '))
if s == 'quit':
break
print('Length of the string is', len(s))
print('Done')

What I mean is that when I add just input like in the book the code doesn't run. Why is that?

  • What do you mean *"add just `input`"*? Where? Which version of Python (3.x or 2.x)? Is that the indentation you're really trying to use? – jonrsharpe Oct 03 '14 at 13:19
  • 1
    whats your python version ? `input()` is for python 3.x... run this command `python --version` on terminal ! also you have bad indentation !!! – Mazdak Oct 03 '14 at 13:19

2 Answers2

1

If the book is using Python 2.x, only raw_input will work. If you are using Python 3.x using input() will be fine.

Kai Mou
  • 284
  • 3
  • 20
1

In python indentation is very important, it defines code blocks (indentation replaces { and } in many others languages like c/c++/java/etc...)

Try to re-indent your code correctly.

This code runs fine :

while True:
    s = (raw_input('Enter something : '))
    if s == 'quit':
        break
print('Length of the string is', len(s))
print('Done')

Another note : don't run your code directly from a text editor (like sublime text) because raw_input is often captured by the text editor.

DomDom
  • 76
  • 5