python - 从Python 3移至Python 2

标签 python string list if-statement compiler-errors

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/

相关文章:

python - 如何将groupby多索引转换为Pandas中的新列?

python - 如何沿曲线注释文本

python - 如何比较列表中连续整数的最后一位数字?

string - String init(format... 方法有问题吗?

c++ - O(1) 反转字符串

python - 如何使用python通过移动一行在csv文件中创建新列

c# - 如何在从整数数组创建的列表中使用 ANY?

python - Flask中初始化DB的地方

python - python多处理中的共享变量

java - 字符串数组的拆分和排序