Discuss / Python / 上课心得

上课心得

Topic source
a=int(input('请输入a的值:'))
if a>=0:
    print(a,'是非负数,绝对值为',a)
else:
    print(a,'是负数,绝对值为',-a)

阿蕾002

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

我尝试了用你的代码,但是命令提示符一直说第二行if出了问题,求解

a=input('please enter a')
if a>=0
    print(a,'是非负数,绝对值为',a)
else,
    print(a,'是负数,绝对值为',-a)

阿蕾002

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

else后面的“,”改了也没用,是if行出错了

ChangingFond

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

你的if行后面少了个冒号

阿蕾002

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

改了之后还是不行,还是那一行,invalid character in identifier

include06

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

你的a和>之间应该有个空格

include06

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

=和0之间也应该有个空格

阿蕾002

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

谢谢 之前没有看到你的回复。学到后面发现是需要首先把input的内容转换成int类的。因为input进去的内容是算作字符串的。


  • 1

Reply