0
print('10 -> 2 [bd], 2 -> 10 [db]')
answ=input('select db or bd : ')

if  answ == "db":
a=input('enter a digit')
x=int(a)
list1 = []

while (x):
    x%2
    x//2

    if x==0:
        break

I began creating this on python 3.2, but then I had to move on python 2.7.5 and I get the following error message:

Traceback (most recent call last):
  File "C:\Users\<file path>", line 3, in <module>
    answ=input('select db or bd : ')
  File "<string>", line 1, in <module>
NameError: name 'db' is not defined
>>> 

I really don't know hat is all about, worked pretty fine on python 3.2 (sorry for my bad english).

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Marcel Chyra
  • 5
  • 1
  • 2

2 Answers2

4

You need to use raw_input:

answ=raw_input('select db or bd : ')

input in Python 2.x evaluates input as real Python code.

Also, just a tip: these two lines:

x%2
x//2

don't do anything. Perhaps you meant:

x %= 2
x //= 2
  • And for more information [this question](http://stackoverflow.com/questions/4915361/whats-the-difference-between-raw-input-and-input-in-python3-x) has details. – Andy Oct 14 '13 at 20:04
  • @MarcelChyra - Hmm, that is very strange. I ran the code in Python 2.7.5 and I didn't get the error at all. –  Oct 14 '13 at 20:09
2

In python 2 the equivalent to input is called raw_input

so line 2 should be answ=raw_input('select db or bd : ')

http://docs.python.org/2/library/functions.html#raw_input

James K
  • 3,692
  • 1
  • 28
  • 36