Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 项目必须结束,但最终获胜';停不下来_Python_Math_Division - Fatal编程技术网

Python 项目必须结束,但最终获胜';停不下来

Python 项目必须结束,但最终获胜';停不下来,python,math,division,Python,Math,Division,我试图建立一个程序,控制一个整数是否可以被“9”整除。我有这个密码 import sys a=int(sys.argv[1]) if a < 1: pos_num= a*(-1) b=map(int, str(pos_num)) c=sum(b) print(c) else: b=map(int, str(a)) c=sum(b) print(c) if c > 10: d=map(int, str(c))

我试图建立一个程序,控制一个整数是否可以被“9”整除。我有这个密码

import sys
a=int(sys.argv[1])

if a < 1:
    pos_num= a*(-1)
    b=map(int, str(pos_num))
    c=sum(b)
    print(c)
else:
    b=map(int, str(a))
    c=sum(b)
    print(c)


if c > 10:
    d=map(int, str(c))
    d1= sum(d)
    print(d1)
elif c==9:
    print("yes")
else:
    print("no")


if d1 > 10:
    e=map(int, str(d1))
    e1= sum(e)
    print(e1)
elif c==9:
    print("yes")
else:
    print("no")


if e1 > 10:
    f=map(int, str(e1))
    f1= sum(f)
    print(d1)
elif c==9:
    print("yes")
else:
    print("no")
导入系统 a=int(sys.argv[1]) 如果a<1: pos_num=a*(-1) b=映射(整数,整数) c=总和(b) 印刷品(c) 其他: b=映射(int,str(a)) c=总和(b) 印刷品(c) 如果c>10: d=映射(int,str(c)) d1=总和(d) 印刷品(d1) elif c==9: 打印(“是”) 其他: 打印(“否”) 如果d1>10: e=map(整数,str(d1)) e1=总和(e) 打印(e1) elif c==9: 打印(“是”) 其他: 打印(“否”) 如果e1>10: f=映射(int,str(e1)) f1=总和(f) 印刷品(d1) elif c==9: 打印(“是”) 其他: 打印(“否”)
问题是,当整数不大时,例如“27”,程序将显示它没有“d1”的值。有人有什么建议吗?

将整个程序替换为

import sys
print("yes" if ((int(sys.argv[1]) % 9)==0) else "no")

将整个程序替换为

import sys
print("yes" if ((int(sys.argv[1]) % 9)==0) else "no")

print(a%9==0)
print(a%9==0)
?当然,您看到的错误是因为d1只在c>10时定义。@Jaques F。我总是说什么是执行此操作的最少代码量,如果您能想出的代码长度不合理,那么可能有一种更短更快的方法,毕竟这就是计算机的用途。当然,你看到的错误是因为d1只有在c>10时才被定义。@Jaques F。我总是说什么是最少的代码量来做这件事,如果你能想出的不合理的长,那么可能有一个更短更快的方法来做,毕竟这就是计算机的用途。