I am trying to build a program that controls if a integer is divisible by '9'. I have this for the code.
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")
The problem is that when the integer isn't big for example '27', the program will display that it doesn't have a value for 'd1'. Does someone have a suggestion?
Replace the entire program with
import sys
print("yes" if ((int(sys.argv[1]) % 9)==0) else "no")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.