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
我开始在python 3.2上创建此代码,但是随后我不得不在python 2.7.5上移动,并收到以下错误消息:
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
>>>
我真的不知道帽子的全部含义,在python 3.2上工作得很好(对不起我的英语不好)。
最佳答案
在python 2中,相当于input
的名称称为raw_input
所以第二行应该是answ=raw_input('select db or bd : ')
http://docs.python.org/2/library/functions.html#raw_input
关于python - 从Python 3移至Python 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19368315/