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/?

18th Apr 2020, 11:41 AM
Chaniza Van Sinda
Chaniza Van Sinda - avatar
12 ответов
+ 4
Add ,trim() to nextLine() it's added in my code now https://www.sololearn.com/discuss/2172728/?ref=app
18th Apr 2020, 3:55 PM
ChaoticDawg
ChaoticDawg - avatar
+ 5
Thanks, 3rd case has space in the first input. nextInt trims it automatically, but Integer.parseInt doesn't.
10th Apr 2021, 11:14 AM
Dmitry Lezin
Dmitry Lezin - avatar
+ 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.
18th Apr 2020, 1:32 PM
ChaoticDawg
ChaoticDawg - avatar
+ 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
18th Apr 2020, 1:13 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Divide by zero has been handled in my code
18th Apr 2020, 3:28 PM
ChaoticDawg
ChaoticDawg - avatar
+ 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
8th Apr 2021, 11:14 AM
Dmitry Lezin
Dmitry Lezin - avatar
+ 1
It's a bad idea using nextLine on single integer inputs, unless the input is a row of integer values separated by spaces.
10th Apr 2021, 11:31 AM
Jan
Jan - avatar
0
ChaoticDawg Testcase #3 still not passed after I tried your suggestion
18th Apr 2020, 2:56 PM
Chaniza Van Sinda
Chaniza Van Sinda - avatar
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..
18th Apr 2020, 3:26 PM
Jayakrishna 🇮🇳
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
9th Apr 2021, 9:11 PM
Jan
Jan - avatar
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')
10th Feb 2022, 6:45 AM
Gelndjj
Gelndjj - avatar
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")
13th Feb 2022, 7:50 PM
Przemysław Komański
Przemysław Komański - avatar