+ 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')

4th Apr 2022, 11:10 PM
Anna Mitrofanova
5 ответов
+ 5
You can also use all() function. if all([not a%int(i) for i in b]): print("all") else: print("not all")
5th Apr 2022, 12:02 AM
Simba
Simba - avatar
+ 4
a=int(input()) for i in input().split(): if a%int(i): print('not ', end='') break print('divisible by all')
5th Apr 2022, 3:19 AM
Brian
Brian - avatar
+ 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.
12th May 2022, 4:04 PM
MING ZI CHEN
MING ZI CHEN - avatar