0
Code Coach Divisible
In Code Coach Divisible, test case #3 won't pass. Can someone help me? Here is my code https://code.sololearn.com/c7BofwAGxAdb/?
13 Réponses
+ 4
Add ,trim() to nextLine()
it's added in my code now
https://www.sololearn.com/discuss/2172728/?ref=app
+ 5
Thanks, 3rd case has space in the first input. nextInt trims it automatically, but Integer.parseInt doesn't.
+ 2
Piyush Srivastava
The parsing is to convert the input type from its default of String to int. This is correct and necessary in order to do the mathematical calculations without having a type error. The split is needed as well. The second input is a space separated string of numbers so they also need to be converted after being split into an array which is iterated over to check if each number in the array is a factor of the first number input.
+ 1
I don't have pro, but my guess would be that you are missing a use case. Without knowing the challenge definition I can only speculate.
I'm guessing that you are being given a 0 as a possible divisor and thus are receiving a divide by zero error. I modified your code to reduce it and added a return false for a 0 (again reread the challenge definition and make sure you are covering all possible use cases).
https://code.sololearn.com/ccCLGZUuQM5H/?ref=app
edit: fixed my error in code.
whoops forgot to test it prior to posting. lol
+ 1
Divide by zero has been handled in my code
+ 1
3rd case has a bug: it doesn't pass neither "divisible by all", nor "not divisible by all".
https://code.sololearn.com/c0V2m0mMzwiV/?ref=app
+ 1
It's a bad idea using nextLine on single integer inputs, unless the input is a row of integer values separated by spaces.
0
ChaoticDawg Testcase #3 still not passed after I tried your suggestion
0
May be, if input contains 0, then it raise exception so it need to handled as special case.. By try catch..
If you still, don't get that way, then try to put description here.. That may help to analize the program correctly..
0
There is no bugs in any of the test cases. My code didn't have any problems.
https://code.sololearn.com/cLIyqexxa3Yo/?ref=app
0
num=int(input())
div=input().split()
div_int=[]
count=0
for i in div:
div_int.append(int(i))
for i in div_int:
if num%i==0:
count+=1
if count==len(div_int):
print('divisible by all')
else:
print('not divisible by all')
0
number = int(input())
groupNumbers = input().split(" ")
amount = 0
for x in groupNumbers:
if number % int(x) == 0:
amount += 1
if amount == len(groupNumbers):
print("divisible by all")
else:
print("not divisible by all")
0
Say a word not understand