8 kyu
Fix the Bugs (Syntax) - My First Kata
3,636 of 10,773donaldsebleung
Loading description...
Debugging
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Why I get ZeroDivisionError: integer modulo by zero. How to address if a or b is zero? The instructions only say 'If a and b are both numbers, neither of a or b will be 0.'
An issue is a bug with the kata, this is not an issue. This is caused by your code. Try printing the inputs to see why your code is dividing by 0. Also, see the comment and reply directly below this one.
.
it's not a kata problem you need to filter out anything that isn't a number in kata there are no zeros.
But the random tests give me
ZeroDivisionError: integer modulo by zero
in Python3
That's because booleans are also instances of int. And in Python,
0 == False
.Not ideal description but thank you anyway! Keep trying to do something that inspires you :-)
Nice Kata, bro
not a suggestion. ;)
"Hello, this is my first Kata so forgive me if it is of poor quality" -> Don't be afraid, you are forgiven!
I've passed the kata, didn't change anything, passed my second submission. There is something wrong with the auto generated test cases
We can't read your mind, please give actual details.
This comment has been hidden.
User solved this in PHP only.
I found no issues with their solution & the random tests (positive number tested only) that prevent them from passing this kata.
Resolving this. (to blame cosmic bit flips)
python new test framework is required. updated in this fork
If you're going to add floats then they should at least count as valid numbers per the specs, but this will invalidate all current solutions so just don't add them.
Also random tests in general look spotty, rather than generating a fixed set of random values that you reuse just make new ones for each call.
The problem states that if the arguments are numbers then it can be assumed that neither will be 0. But I am getting a division by zero error in the random tests.
the python translation doesn't consider booleans numbers even though they are
there's also javascript logic partially and inconsistently leaked into it, in js there's no integer type (unless counting bigint) and instead there's a number type which is just float.. but the python translation uses int.. it's not clear at all how that should be fixed if it was to be changed.
Funny in JS. Thank you!
This comment has been hidden.
ChatGPT confirms my function (in JS) is correct but it won't pass the tests. Any pointers? Not sure where I am going wrong (not sure that I am to be honest!)
In my case I had zero division and a test with a boolean that was passing as integer failing...
The kata should also have test for float values considering that real values(float) are also numbers
Your katas have improved a lot since then :)
Ruby 3.0 should be enabled.
Enabled in this fork
First it was giving me 1 error. I hit attempt again with the same code. It was 2 error. I tried again. And finally it was passed all with the same code. :D
same here with my code, I also tried the most upvoted solution and same thing happened :)
lol the same. press attempt 3 times and finally 0 errors xD
Small quibble: Duck typing is best practice in Python, and also in Python3 booleans are a subclass of integers, meaning that arithmetic will work between bools and ints. However, when a boolean is passed in the random tests, a "False" is expected, which would force a programmer to use type-checking. Since this is an 8 kyu kata, and likely to be teaching new programmers, I would suggest either changing the expected value of those tests to reflect booleans as a number, or just removing booleans from the Python random tests entirely (if you think that this issue is over the level of an 8 kyu).
This comment has been hidden.
Great job on a first kata. These debugging Kata are great as debugging is a skill required for any coder.
Gosh... this Kata should not be giving me these feelings of rage xD
Good job at reminding people why debugging code of people new to a language is so irritating to find yourself having to do xD
According to kata description:
You may assume the following:
If a and b are both numbers, neither of a or b will be 0.
but unfortunately, when I check my solution, appeared this error:
return (a % b) + (b % a) ZeroDivisionError: integer division or modulo by zero
I did this kata in python.
Me too. Maybe it's just a wrong explaining of the excercise...
It appears that now that we have Ruby 2.5.0 available in Codewars that some of the tests are causing a warning as they are using Fixnum which has been deprecated... This is causing answers to fail that should be valid (they still work in 2.3.0)
It's too hard kata, indeed :) Thanks!
For the dynamically-typed languages, the tests should cover all possible numeric types since the description specifies only that arguments must be numbers. That, or the description should say integers.
This comment has been hidden.
CoffeeScript Translation Kumited! Please Accept :D
Approved, thanks for your contribution :D
TY! :D
I enjoyed this kata quite a bit. Well done!
The output frame lights with green, but it writes that I have 1 Error, but I haven't nothing in console
Good kata for beginner
Thanks for the compliment :)
I ended up using typeof but i really wanted to use parseInt... didnt know about isNaN().
The instruction false/False`` plusb % a``` if both arguments are numbers confused me as I wasn't sure if I was just supposed to print the output as " " + b + "%" + " " + a . The output result seemed to have shown numbers instead of an evaluated result. All in all, a really good practice for beginner like me. Need more practices like this.
Sorry, that seems like a description bug. Thank you for the report and I will fix it.
This comment has been hidden.
Hmmm ... it seems that the Python translation for this Kata is indeed a bit bugged. Please contact GiacomoSorbi to inform him of this bug.
Thank you very much :)
Cheers, donaldsebleung
Actually I think the problem is more about math.isnan working for floats, not ints. Also, try to post code with a triple back tick in the beginning and end, as it helps readability :)
I cannot see which strings would be generated here...
'Looks like you've solved it'
This comment has been hidden.
Hello bugman4,
The code displayed above looks like Python to me, which is just an approved translation from GiacomoSorbi. In cases of doubt/issues please contact him.
Thank you very much.
Cheers, donaldsebleung
Thanks for your respons :)
Your code is not correct, as it works even for boolean values, while it should not (or rather: it should throw an error).
Hope this helps :)
however, the test may pass the incorrect code sometime,
so I suggest that the test should include the boolean case all the time;
Love this Kata. I just started learning JS a few months ago. It's hard to find good excercises for beginners.
Keep them coming! ;-)
Thank you for your support, I will make sure to create more Katas of this type in the near future :D
As a general rule, it's not a good practice for a function to return different data types based on the input. I suggest throwing an error when the arguments are invalid.
Thank you for your feedback. Forgive me if this Kata isn't of top quality or contains bad practice - after all, this is the very first Kata I have created on Codewars.
However, I will make sure to keep good practices in mind when making future Katas :)
Cheers, donaldsebleung
It was not criticism, just a suggestion. Waiting for your next ones ;)
The description should specify the return value when one of the arguments is zero. I would think that it should return False in this case. The test cases should test for division by zero.
Thanks for the feedback ecolban, I forgot to consider division by zero when making this Kata but for simplicity I think we may assume that both
a
andb
are non-zero provided both of them are valid numbers.I will make sure to consider corner cases in my future Katas :)
The Python version of this kata doesn't provide any code. That makes the instruction "In this Kata you should try to fix all the syntax errors found in the code." very confusing.
Hello rbeer,
That is true; only the Javascript version of this Kata is bug fixing, in both Python and Ruby you pretty much have to code it from scratch because they are approved translations created by other users who have contributed to this Kata.
However, instead of changing the exercise itself (Python/Ruby version) maybe I will simply edit the description to make it clearer what is expected in each language.
Thank you for your feedback.
Cheers, donaldsebleung
Description updated. Objective should now be clear in every approved language.
Issue resolved.
This comment has been hidden.
Thank you rbeer for your alternative Python translation. However, I am not positive that your working solution passes all tests as when a number is passed in as a string, your program does not handle it properly according to the established Python test cases.
May you please fix the code for the working solution so it passes all random tests every time? Once the problem is fixed I will use your Python translation as it more accurately reflects the original intent of this Kata.
Cheers, Donald
Sidenote: Next time if you want to publish a Kata translation, you may want to click on the "plus" sign on the language selection bar and do it the official way - this way, you will gain honor every time a Kata translation is approved ;)
Changed the code template, now is properly bug fixing for every language; thanks for the feed :)
Nice beginner kata; translated into both Ruby and Python if you want to approve them (and let me know if you cannot see two translations).
You might then want to use
Test.describe
andTest.it
instead of mereconsole.log
s to add messages and group your code. Let me know if I might be of some help :)Thank you for the translations; I have approved the Ruby version :) May you please provide me with the link to your Python translation? I can't seem to find it.
My pleasure, as it seems to be a recurring bug: here you have it :)
Thank you, both translations should now be approved.
EDIT: Hi GiacomoSorbi, as a side note may you please teach me how to use
Test.describe
andTest.it
in Javascript (if possible)?GiacomoSorbi has my respect for being a nice guy.
I like challenging myself against GiacomoSorbi level guys
Oh, I am just a mere amateur with a lot of persistence and really a lot more still to learn, trust me that I am not that big, particularly compared to other top rankers which I deeply respect ^^'.
Anyway, both
Test.describe
andTest.it
work in the same way, meaning they group tests (which in itself is quite useful, so you can try and possibly miss a few of them in a single click instead of stopping execution at the first error - i.e.: you get something like "12 tests passed, 3 errors").describe
is usually the "father", having under him 1 or more.it
. Their syntax is quite simple, like:Test.describe(*message*, testFunction)
.In plain JS syntax, you would write something like:
Test.describe("Basic tests",function(){ *all your tests here* })
With more "modern" JS, currently already supported by CW, you can go for arrow notation, so the above becomes:
Test.describe("Basic tests",_=>{ *all your tests here* })
Hope this helps, let me know if not or if I can support you some more to the extend of my meager skills :)
Thanks a lot GiacomoSorbi, I will utilize them in my future Katas.
My pleasure; for everything you might deem me useful with, feel free to contact me on our gitter channel or, if you wish, I can give you my private email :)
Greate kata man! :)
Thank you very much :D
Great kata in general and good to hear that you started writing your own katas. keep it up :D
Could do with some random test cases to prevent hardcoded solutions :)
Also assertEquals should have the actual then expected values passed in
Thank you for the feedback. I have made the requested changes.
Great, that you started at writing your own katas!
To increase your kata's quality you should provide some example test cases. Especially in your kata it's not absolutly necessary, but in general, it will help codewarriors to understand what the got to do.
Thanks a lot Julz, will add example test cases in my next Kata :)
I didn't add example test cases in this kata because I wasn't familiar with the interface yet and was not sure what it would do.
No problem ;)