+ 1
Code coach DIVISIBLE (python)
Is there a way to simplify the code? *** a=int(input()) b=input().split(' ') c=0 for i in b: if a%int(i)==0: c+=0 else: c+=1 if c==0: print('divisible by all') else: print('not divisible by all')
5 Respuestas
+ 5
You can also use all() function.
if all([not a%int(i) for i in b]):
print("all")
else:
print("not all")
+ 4
a=int(input())
for i in input().split():
if a%int(i):
print('not ', end='')
break
print('divisible by all')
+ 2
x = int(input())
test = list(map(int, input().split()))
rem = [x % num for num in test]
if any(rem):
print('not divisible by all')
else:
print('divisible by all')
#The any() function returns True if any element of an iterable is True. If not, it returns False.