Discuss / Python / 运算报错

运算报错

Topic source

CindyChen83

#1 Created at ... [Delete] [Delete and Lock User]

按照教程里面的运算:

s = input('birth: ')
birth = int(s)
if birth < 2000:
    print('00前')
else:
    print('00后')

这个的运算结果是报错的

如果直接按照简洁的写法,才是正确的:

birth=1988

if birth<2000:

  print('00前')

else:

  print('00后')

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

请贴出你的错误;

初学者要坚信错的是自己。

凡响skyline

#3 Created at ... [Delete] [Delete and Lock User]

input返回的值都是字符串类型的,要用int()转换成整型才能与整数比较

CindyChen83

#4 Created at ... [Delete] [Delete and Lock User]

s=input('birth:')

birth: 1988

birth=int(s)

if birth<2000:

  print('00前')

else:

  print('00后')

Challen18

#5 Created at ... [Delete] [Delete and Lock User]

标点符号是中午输入法输入的吧


  • 1

Reply