8 kyu
Even or Odd
1,149 of 563,427suuuzi
Loading description...
Mathematics
Fundamentals
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.
it uses different version of C language which would be different than what i use, i use C17 and somehow it isnt available here
This challenge works with every version of C language. You are approaching it incorrectly, not in a way how Codewars challenges should be solved. See if this article helps.
my issue is bc i'm french haha i wrote "nombre" instead of "number" in english.
First time in codeWars !
my issue were the wording Even instead of even, same for Odd instead of odd.
This is a great exercise for those who want to start with confidence! If you read this, keep practicing, programming is funny!
Thanks
was fun! on my first attempt, i tried to make nested functions for odd + even, but ended up realising i could just nuke it xD. hope we all have nice coding journeys!
Hello world
GTYBC
Simple challenge for beginner coder. We will only get better from here guys ;)
This comment has been hidden.
This paragraph should answer your questions.
This comment has been hidden.
Bugged kata, -21 and -977 are not even.
And who says they are? Can you explain what the problem is exactly?
Your solution causes following error:
Your solution incorrectly returns
"Even"
for n=-21.Bugged user.
how to do the test any coding. whatever i type it shows error
Found it in the below comments
Hardest Kata ever (in BF)
very nice problem!
Ugh, I thought it would be more difficult. If you are stuck, catch my support!
Hi everyone, there is a problem with table Numbers. Even simple query 'select * from Numbers' returns error
You don't have to create a new table. You are supposed to write a
SELECT
query. I will clarify this in the solution setup.Ok, but why on SQlite simple query doesn't returns an error and on PostgreSQL returns?
Because these two behave very differently. Most of the challenges are intended to be run with Postgres.
Thanks, I passed!
Maybe mb but I didn't read the solution setup, as it was written awkwardly. No intent updating the Details?
I have the solution, but the test, say it's wrong :/, who can help me ?
This comment has been hidden.
yes also saw and i changed again. so now the name of the function is evenOrOdd.
and the error:
ReferenceError: even_or_odd is not defined at /home/codewarrior/index.js:12:10 at /home/codewarrior/index.js:16:5 at Object.handleError
so i think this task is not difficult but i got some error :)
But your current code passes all tests. Did you modify sample tests for this error to happen?
No, i never touch the original test :/
Either copy your code and hit Reset button at the bottom, or simply click Attempt. I don't see how it wouldn't work, I ran it myself and it passed.
now working :) after the reset! thx :)
It's too easy
It's supposed to be easy
This comment has been hidden.
It's not
2 == 0
, there is something else before it. You should try following some tutorial to get familiar with fundamentals of the language before solving katas.The index starts at 0. I used the modulo % to add 2 to the power of 0. This = 2 and also = Even. no need for anything else as the remander and only have aone result. That is = 1 and is Odd.
I suck at explaining and doing math so my appoligies in advanced for the crude explanation. However that is how I got passed this Kata. I also tried to explain without giving the whole thing away.
thank you very much i understand now.
i will leave this here: the "" is where you write your code not some 'string' thing, i got very confused tbh.
This comment has been hidden.
wrong the first time because of identity. OH MY GOD
This comment has been hidden.
N0pE. It has been solved by over 140K coders in your language alone.
you are trying to print the input
instead you need to return a value
Thanks! I tried just returning the string , and it worked. I guess i am used to printing strings not returning them.
This comment has been hidden.
its too hard
Maybe, if you're trying it in BF.
This comment has been hidden.
You were alreay asked to not post solutions in kata discourses. Please don't do this.
sorry, its my first time in the website and idk how to post the solution in the solutions section, anyway wont do it again mb
You do not need to post your code to the "Solutions" section, it appears there after you click the "Submit" button after passing tests. Your solution for this kata is here (grouped with a thousand of other users). You can see it by using the "View: Mine" filter on the solutions page.
In this type of challenges, when the solution is relatively simple, I enjoy devising a response that intentionally complicates the situation.
Just a simple question to test us beginners :fire
how to submit solution?
See if this helps: https://docs.codewars.com/training/training-example
the cursor is not coming down even though you press enter
Hello everyone, who finds it difficult to solve the problem, don’t worry, don’t rush, we are all learning here and what seems difficult at first will become simple over time. Just find out how to determine whether a number is even or not. And then simply based on this number, return the string ("Even" or "Odd")
thanks mane u really helped my morale here
This comment has been hidden.
Your code is very close to being correct!
The name of the column alias should be given without 'single quotes', it should be
AS is_even
.would have been easier if i knew i wasn't allowed to use print and expected to use return instead xD
It's somewhat implied by the "Create a function that [...] returns ...".
Also it's kind of documented.
well i didn't really read that, so much as just started playing around with the challenges :') but i got there in the end, just thought i'd leave a comment in case someone did the same thing as me xD
Thanks so much!!! I thought this challlenge was relatively easy, but it would throw up errors every time until I saw your comment!! Lifesaver!
This comment has been hidden.
This comment has been hidden.
Your solution is already present in the solutions tab for all to see and discuss. Sharing it under discourse - unformatted, no less - is redundant. Even if you mark it as spoiler, it will still spoil it for those who solved the Kata in other languages but not JavaScript yet.
This comment has been hidden.
See https://docs.codewars.com/training/training-example.
This comment has been hidden.
Please don't:
Not a kata suggestion. See https://docs.codewars.com/training/troubleshooting#post-discourse.
This comment has been hidden.
On Codewars, you don't work with input/output. You instead have to write functions that return values.
Here's an overview of how it works: https://docs.codewars.com/training/training-example
Thank you so much B1ts - that's really helpful and appreciate the lightning response!
The problem was a good one for begginers to boost their confidence. One can solve this just by checking the rightmost bit of the number : if the bit is 0, the number is even else odd.
that breaks however if you submit 2, instead of 2.0
This comment has been hidden.
Good job, thanks P.s.: doesn't work
This comment has been hidden.
You shouldn't add anything to the table, you only need to execute a select statement.
As Chrono79 wrote, don't add anything or alter the given table. In SELECT statement, you can define a new column in you output and wrote a constant or formula to populate that column. Use this.
very nice problem!
This comment has been hidden.
Not a kata suggestion. See https://docs.codewars.com/training/troubleshooting#post-discourse.
This comment has been hidden.
You're making mistakes that users that are new to Codewars make. This article should help you understand what the tests expect from you.
This comment has been hidden.
Your function should return the result instead of printing it. Please mark your post as having spoiler content next time.
im writing it in c++, it gives error for int main() dk why tho, anyone can help?
Try asking on Discord. You need to write a function that returns a value, not use
cin
orcout
.First of all, you have missed the main keyword. Also the if-else syntax is wrong.One more thing, you need to return one of the strings "Even" or "Odd", not print it.I would suggest you to first learn the basic syntax of the language, then try solving the problems.
This was such a good introdyuction to coding! Thanks for making this?
agreed this was kinda fun
what was your solution to it
o thanks for the comment buddy! Glad you agree!
well... I kinda just... did it, you know?
how tho im curioustg
Well, I kinda just solved it with the code, you know? Where if you put in the right code, you get the right answer
i wanna learn tho
Well then, watch a youtube tutorial or smt
shush man
they move to fast and are too complicated tho
tbh im starting to think you havent done it
just tell him how to did it its not that hard
@darksloth18, be nice, we're all learning something new on our programming journeys. @CodingLearner95, you've got this! I'm sure you'll find some useful tutorials out there, and keep practicing katas :)
thank you this has motivated me and i just did a 7 kyu
Good job codinglearner96! You are really growing as a coder!
THANK YOU :))))))))))))))))))))))))))))))))))))))))
but how did you do it ClabeBARERBEBRE im really proud of my solution, imagine we did the same thing XD that would be really funny and cool. Also how much is it to rank up to 7 kyu
its codinglearner95 btw not 96
vanessa how many have you done, ive done 4 and are still at the easiest level like you
Be nice, ppl.
codinglearner leave clabe alone bru
clorance sammy
i dont evn know what that means
clabe ius my friend btw
Would you people find some instant messenger software to chat? Just stop spamming and unnecessarily inflating this thread, would you.
Also please do not reply to this message.
@hobovsky no u
it is perfect for me now, thanks
Raku translation.
Prolog translation from B1ts.
My first kata , the logic was very easy , just find odd or even , but i didnt know how to use the site , didnt read the question well and messed up a few times lol .
Fortran translation.
.
This comment has been hidden.
Please use appropriate markdown formatting when posting code. See https://docs.codewars.com/training/troubleshooting#post-discourse.
You're printing instead of returning. From the description:
See https://docs.codewars.com/training/troubleshooting#.print-vs-return and https://docs.codewars.com/training/training-example.
Noted. Thank you
Forth translation
Approved.
please make another game!
RISCV Translation to invade hobovsky translation monopoly! LoL
I am not doing translations as much as forks which change existing translations, because I am running a small experiment and I picked this kata as a guinea pig: I want to turn it into an example of authoring practices so others could use it as an example to guide new authors about creating kata, tests, setting up snippets, etc. Whether it will work out well or not, we will see. I have not finished yet :)
If you want to make your translation conformant with the idea, please take a look at tests of C or NASM translation and make this one as similar as possible w.r.t. orgaization of tests, test groups, feedback on failure, dedicated generators for various types of inputs, etc. I can write a comment on the translation with explicit points I would like to have changed, if you want. If you don't want to, I can just merge it as it is and I will adapt it later.
Thanks for the translation!
Just noticed your message! Will answer you later... But defintely riscv is a different language with different opportunities and needs a different test coverage...
Approved, with a follow-up fork for unification with C and NASM translations.
this will give you correct answer
This is not a kata suggestion.
that means "you can do anything to take correct test case" there is no procedure for that
The kata
suggestion
tag is for when someone has an idea on how to improve the kata. It is not about providing guidance to the coders solving the kata.Maybe the op means i broke something in some language and tests always pass? :thinking:
Turns out their only language is Java, for which tetsing functions normally.
The print is not needed in the body of the cycle. create a common variable for return and assign to it variables to which the values Even and Odd are assigned.
why my code does'nt work someone please explain me what's wrong i did
We don't know what your code is, so it's hard to tell, please read this: https://docs.codewars.com/training/troubleshooting
You passed this kata in Python so I'll close the question because maybe it's not valid anymore.
It's my first time using this kata so I was pretty cofused at the begining. the function head is already given, just write the operation you will use to find even & odd numbers with return statments and don't forget to make the first letter capital. hope this helps!
This comment has been hidden.
kata hint != kata suggestion
I didn't like this Kata whatsoever. My code was wrong because it didn't have uppercase letters.
okay... but the tests tell you that, and fifteen seconds later you've got it fixed
Rust fork with random tests: https://www.codewars.com/kumite/64ebde01f1294fdf8f4358f6?sel=64ebde01f1294fdf8f4358f6.
Approved by someone.
👀👀
TS: method name should use
camelCase
Oh I closed the issue too soon, sorry, I missed that one language is still not changed.
Fixed.
This comment has been hidden.
Please:
See https://docs.codewars.com/training/troubleshooting/#post-discourse.
You should return your output, not print. See https://docs.codewars.com/training/training-example/#writing-a-solution.
Not a kata issue.
why are you returning the i, its like you go to a shop and when asked the shopkeeper is giving the money to you again without giving the goods. return the answers not question.
This comment has been hidden.
3 times i do the same logic for even or odd at first and seeking for wrong capitalize letter but it seems like no error should appear and i see hint answer it is same as i do, but after i code on my self editor and see the auto format in code like if else should be end with end syntax. LOL i just forgot end in the end of my if else:")
epic kata
This comment has been hidden.
Please read this: https://docs.codewars.com/training/training-example and this: https://docs.codewars.com/training/troubleshooting
Acho que o que codewars vai testar seria o return da função, então desde que a função de o retorno correto "Even" ou "Odd", é para funcionar. Basicamente, não use print
"Odd" and "even" are the wrong way around. Thats why it's not working. It's asking for the opposite in the question.
What's the other way around? Do you know what odd and even mean?
The tests are fine.
Nope, my bad you a totally right. I read the question wrong. For some reason I thought the question was asking to do the opposite. I got it correct regarless. its 00:00 over here, its way passed my bed time!
I realised thet print func isn't a solve. solve is in return function
Yes, that's written in the Troubleshooting
Nice, you fixed the errors I was getting. GG WP
Iam very bad with this
Good Kata! There is nothing worng. You just need to read carefully :)
there is something wrong with the test cases as they not compling with the instructed code
There is nothing wrong with the tests. The function's name should be
evenOrOdd
noteven_or_odd
. Not a kata issue.I used way to long for this, Overthinking it. Its natural i think to complicate things more then it needs to. Its a very simple solution, it might take you some time to solve it, but its a good practice.
This comment has been hidden.
"I did something wrong" is not a kata issue.
Please see this: https://docs.codewars.com/training/training-example#writing-a-solution
This comment has been hidden.
Please mark your post as having spoiler content next time.
This comment has been hidden.
if your forloop starts with number = 0 then number > 0 will never be true so your code will allways return "Odd"
THE PROBLEME IS WHEN YOU Don't USE CAPITAL LETTER IN TE WORD "Even" or "Odd"
This comment has been hidden.
You're printing instead of returning. Please read this article that explains how the codewars trainer works.
Also, you should use appropriate formatting (code blocks) when pasting code.
my code seems to work but it keeps failing. I guess the problem is in the way i'm displaying the code but can't find a way through it yet
This comment has been hidden.
Because you should return the result, not print it to the console. That Information is also in the CW Docs, make sure you read them. Please mark your post as having spoiler content next time.
Confused for a solid 10 minutes, turned out single quotes arent the same as double quotes...
This comment has been hidden.
Because you should return the result, not print it to the console. That Information is also in the CW Docs, make sure you read them. Please mark your post as having spoiler content next time. is also in the CW Docs, make sure you read them.
OMG how basic. Thank you so much!
i dont know what to do 😭
Helps us help you then, the instructions are pretty clear imho, what is it that you don't get?
You know hopefully that it needs to take a Integer and decide whether it's even or odd. How do you know if a number is even or odd?
This comment has been hidden.
man codewars aint noob, beginner friendly. Overwhelming, confusing there's just so much info being thrown at you in the beginning.
Are you talking about this kata? What do you find overwhelming and confusing?
This comment has been hidden.
Hello i need help pasting my code into code wars. I solved the problem in my ide and it works fine but if i upload it onto here i get an error. This has happened for two different problems. Thanks
If you're using Python it probably has something to do with indentation.
You passed this kata in Java, better read troubleshooting guide and post in those katas or check the Discord channels.
Expected and actual are reversed (in Python).
Fixed random tests.
i dont know what to do 😭
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
You have to return the result outside the function and not print it You can see the solution here https://www.youtube.com/watch?v=21dubQbbZ1c&list=PLCzjSL3T_UnRytK3pLwwrX0I26Y9UYY9A&index=9 Subscribe to my channel for more videos.
this is easier than i first thought :)
This comment has been hidden.
Try this question without using arithmatic operators (Level 1). Again try this question without any type of operators (Level 2). This are the follow up questions asked in interviews. You can find the solution for above two questions in this video. https://www.youtube.com/watch?v=21dubQbbZ1c&list=PLCzjSL3T_UnRytK3pLwwrX0I26Y9UYY9A&index=9 Subscribe to my channel for more videos.
Nice cata. Simply and pretty short on JS. Also remmeber me to use ternary)
PowerShell translation
Approved.
This comment has been hidden.
You are right, and you are wrong.
You are right that there can be more than one way to solve a problem. There is more than one algorithm to determine whether a number is odd or even, and your algorithm is a good one.
You are wrong that you can write whatever you want and it should be accepted, because when programming, your code usually has to conform to some interfaces or protocols. It can work however you like (almost), but it needs to communicate with other parts of the system in a predetermined way. You can rant as much as you want, but this doesn't change the fact that your code does not do that: it does not conform to general requirements of a Codewars solution. And it's not problem with just Codewars, because whatever code you are going to ever write, it has to fit into other places of the system like a jigsaw.
For some details, please check if this article is helpful.
Description: "Create a function", OP: pRoMpT()
Did you bypass the coding challenge to be able to register here somehow? It should've showed you that you're meant to write functions that return things to solve katas. Additionally, when you enter a kata, you should see a template of the function you need to write. Ignoring all these things leads you exactly where you are.
for some reason it only lets me relly to you b1ts but how am i even supposed to know what a kata is i never came across that in java scrpit and i couldnt use regular prompt because it kept saying funtion not defined the template had mad extra irlavent code that noone who solved it used lol what are u saying right now and tes i bypassed the challenge because it was broken for me apparently because how woukd my code work other wise?
Did you check the page I linked? Is it understandable?
hobovsky i get tht but how does my code not fit into the parameters? because i didnt know there was a even or odd funtion ig thats idk i never seen an evenorOdd funtion before even a little hit would have been nice but i see your point for sure
The
evenOrOdd
function was there in initial solution setup when you enter the trainer for the first time for this kata, or click RESET. When I enter the trainer, I see this stub:I think it was presented to you too, but you didnt know how to use it, so you deleted it and replaced with your code. Is this possible?
yeah i checked the link thank you now ik but it still dosnt explain why when i put in my code it said it was wrong and also gave me no bug fixes like it shows in the examples the test code also said nothing about an even or odd fucntion its still very miss leading how can i do it there exact way if i the way they want me to model after isnt even anything similar to the final result lol its like a bait n switch
nah didnt show evenorodd on mine could be mistaken though i was bashing my head into a wall for a while everythings hazy at the moment
It said you were wrong because you are expected to return a value, not print to console.
kayleighWasTaken thank you, so i was supposed to make it return a value with no input just a random number?
The general structure of a Codewars problem is that the tests call your function with dfferent inputs and check that it returns the correct value.
This is for consistency (it would be bad UX if some Kata expected you to write to console, and others expected you to return a value, etc. The reason for this being the chosen format is that most langauges unit-testing libraries are structured like this, making test writing for most of them easier.
I don't think there is an issue with my code, because the output seems correct, but codewars shows an error. PS. My code is in the replies. Please help!
This comment has been hidden.
Your code is not exactly correct, and your function does not return correct values even though it seems to.
please see if this page is any helpful: https://deploy-preview-413--reverent-edison-2864ea.netlify.app/training/training-example/
aight, got it, thank you!
This comment has been hidden.
This comment has been hidden.
Please see this draft of a help article: https://deploy-preview-413--reverent-edison-2864ea.netlify.app/training/training-example/ and let me know if it helps!
Additionally, please use code formatting when posting code snippets: https://docs.codewars.com/references/markdown#code-block
you can't use printing on codewars. you have to return a value. returning is basically just assigning a value to a function. you don't need to use input for codewars either, it gives you a parameter which is essentially just a variable that can change every time the function is called
I tried posting my own code to this problem and its giving me errors when I know its 100% correct to find even or odd? How come?
Please see if this explanation is any helpful. It's currently just a draft, and I am looking for ways to improve it.
I'll check it out, thank you!
This comment has been hidden.
I think in the testcases there is a issue why should the undefined value return Odd?
Thre is no test with
undefined
as input. Probably it was your code that was returningundefined
instead of"Odd"
.This comment has been hidden.
This: https://docs.codewars.com/training/troubleshooting#expected-the-same
Try returning the value instead of printing to console. Let me know if that works in js. In python we return the values.
This comment has been hidden.
This comment has been hidden.
You can't use
.at
unless you're using Node v16.6. Read this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at#browser_compatibilityThere is a much easier way to do this.
Thanks sir I wasn't aware about compatibilty properties on katas .
This comment has been hidden.
Not a kata issue, please read this: https://docs.codewars.com/training/troubleshooting
Remove those
print
s, they returnNone
."expected undefined to equel 'Even'" - how it repair? idk where's problem
Your code is printing instead of returning the string. Please read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same
This comment has been hidden.
you need to return the output, not print it
read this to get started: https://docs.codewars.com/
edit: oops, I didn't see that this was already answered. ignore me.
The positive or negative result of the remainder in rust and c++ depends on the dividend, and in python it depends on the divisor
Not a kata suggestion.
This comment has been hidden.
No it doesn't, read this please: https://docs.codewars.com/training/troubleshooting#expected-the-same
Instructions are not clear. It appears that it wants you to create a table named "output" with a column "is_even" and that is not the case.
In JS test fails but all of my answers were correct. I lost a lot of time on this, thinking that I'm dummy :((((
Your current code passes all tests, there is nothing we can do without more info.
This test fails even though the answer is correct. I ran the same test cases that the program would run outside of codewars with all of them passing, yet they all fail within codewars.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#.print-vs-return
Sample tests in SQL are wrong, because they depend on the order the user returns the results.
Fixed.
This comment has been hidden.
You should use a
SELECT
statement, not alter the tablenumbers
.This comment has been hidden.
It seems to work. But if you alter the table then it won't.
This comment has been hidden.
Your function should return the result instead of printing it to the console. Mark your post as having spoiler content next time.
Nice Kata 8, thanks !
help, TEST CRASHED in nasm !!
The error is originated in your code. You're doing really weird things...
callee saved registers
must have the same values at the start and at the end of your function.i think they should give proper instructions
What more do you need?
D translation
approved
I did such a long winded version of this, lol I still don't 100% understand how to use the % operator. Embarrassed with my code but found a way for it to work, so that's a small win for me...
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
very nice kata!!!!
Nim Translation 1.6 fix
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
About your problem, comment out the sample tests or print the input to see which test your code is failing.
This comment has been hidden.
You don't have to input the variable "number", it is given right from the beginning...
This comment has been hidden.
@ZaLiTHkA - I'm not the question-asker but I just wanted to upvote your post; always nice to see high-effort replies and helpful comments.
By the way, you might like the Codewars Discord (link in the sidebar on the left) where there is an active JavaScript channel and your comments would surely be useful to many users there.
Cheers,
^^
This comment has been hidden.
It is a bitwise operator : https://www.geeksforgeeks.org/python-bitwise-operators/
For such a simple kata, you don't really need this.
^^
typescript? no! anyscript? yes!
hello
This comment has been hidden.
Please don't post code without using the Spoiler tag, as it is visible to everyone (including those who haven't solved the kata). Also you can discuss your (and other people's) solution in the Solutions section, not in the Discourse page.
hey thank you, i am new to this platform.......thanks understood how to use spoiler tag
I got gat for not removing the prompt line
Вы издиваетесь?)
Если вы не можете решить эту задачу, проверьте код в функции main().
Не знаю каким образом, но у меня в функции main оказался неверный код, который препятствовал решению задачи.
p.s час потратил на это
p.s.s Kotlin
p.s.s.s Я не знаю, запланировано было это или нет.
This comment has been hidden.
Newbie here, never knew that single and double quotes are different for PostgreSQL lmao
instructions need to be more clear it did not approved my answer because of "" in even and odd
Instructions are clear enough.
without the "" is not a string... thats important
failing the tests despite the code running well with different use cases outside of CodeWars
Read this: https://docs.codewars.com/training/troubleshooting/
I have. Still, nothing.
However it's not an issue (= a bug in the kata).
You have to return the result, not just print it.
This comment has been hidden.
Not sure what your code is, but Xormias is saying that the kata requires you to build a return statement within the function as opposed to printing out the result to the terminal. Additionally many challenges may actually fail if you leave print statements in them due to the way they are built to be checked.
This comment has been hidden.
Because that's what the kata's description says. "Even" and "even" are two different strings. And please mark your post as having spoiler content next time.
Thank you. And I will flag spoiler alert next time
Yeah that got me messed up as well lol. Felt like a trick question but I guess we gotta pay close attention
This comment has been hidden.
On Codwars, input values are provided to your function as input arguments. You are not supposed to read anything with
input
.number
is already the value you should work with.OP solved it, closing
Thanks a lot. I've resolved the problem with your helpful comment.
Easy and good kata!
This comment has been hidden.
It would not work for the kata because your code overwrites the variable number with the result from int(input()).
OP solved it, closing
This comment has been hidden.
This comment has been hidden.
@DainPark-web: Please don't post solutions in Discourse. Code must be posted with a spoiler flag (which makes it invisible to the users who didn't solve the kata). Someone put the flag for you this time.
@nicholasjperry: you have to
return
the result, not print it.Yikes, sorry. Thanks!
Very nice kata for begginer practice.
My code in python in VSCode is correct, but here fail. This kata ir wrong.
how exactly is the kata wrong?
Please read this article and see if you can find anything helpful there: https://docs.codewars.com/training/troubleshooting
OP solved it, closing
Read the instructions carefully, it says return, not print
This comment has been hidden.
you're not supposed to get an input for the code
the function
even_or_odd
will be called with an argumentThis comment has been hidden.
Because your function should return the result. Read this: https://docs.codewars.com/training/troubleshooting/
Please use spoiler flag when you post code.
Please use markdown format tags or it's unreadable, see there: https://docs.codewars.com/training/troubleshooting/#post-discourse
You need to return the result, not print it.
This comment has been hidden.
Yeah I was thinking this would be the best way to solve it too, thanks for your Case hint helped me to find the solution
OP left the building
Negative numbers are not tested in Haskell and should be added to sample test as well
Negative numbers are ( possibly now ) tested in random tests.
Fork with negative numbers in example and fixed tests.
Fork was approved.
This comment has been hidden.
wrong function name ~~
okay but even when I try with the correct one it doesn't work, why?
This comment has been hidden.
what errors are you getting. Also I know its implied by looking at the syntac of your code but always include the language in your write up.
Thank you! This appear: Time: 897msPassed: 0Failed: 45Exit Code: 45 Test Results: Log even Sample tests 2 is even expected 'even' to equal 'Even' Completed in 2ms 7 is odd expected 'odd' to equal 'Odd' Completed in 1ms -42 is even expected 'even' to equal 'Even' -7 is odd expected 'odd' to equal 'Odd'
Ii don't know if there something thara have to be with the sample test?
in expected 'odd' to equal 'Odd'
...
(yours is not capitalized)
Thank you!!!
This comment has been hidden.
Your code being wrong is not a kata issue, those are different operators.
This comment has been hidden.
This comment has been hidden.
Answered then by your acquaintance. Marking as resolved.
I wrote my code in Js and it worked fine in my Vs, I cant submit my solution on code war tho :(
Read this: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Language?
SQL
IF()
is a MySQL function, Codewars uses PostgreSQLPerl translation kumited.
approved
Following
This comment has been hidden.
Sample tests is a tool that evaluates some values as inputs for your code without counting as an attempt. Depending on the type of kata it will compare your code output with the expected result.
When you click on "submit" a whole lot of tests are executed making sure your code don´t break. It´s kind of the same but with random values or at high volumes of data.
So does the syntax have to be perfect for the sample tests to work?
COBOL translation
:)
why the hell is this even 8 kyu.
Doesn't work even with the exact same code, litterally. Like, screened the answer, put it side to side with my solution, no difference whatsoever, and doesn't work.
I feel like there's a bunch of context missing in this comment.
Do you want my solution? Or do you want me to precise that I tried with Postgre ? My solution was clearly the exact same as the first you find in "show me the solutions", hence my confusion.
Do you mean, you tried a solution which you found in the solutions tab, and it didnt work?
That might be because the solution was submitted with an older version of the language
Ok !
My solution was like the first one in the solutions tab
Postgres:
Is there an expected ordering to results? The mapping of strings to numbers is correct but I think results are checked in a different order than I deliver?
There was a bug in the kata which got (hopefully) fixed.
This comment has been hidden.
no u
ur mom
This comment has been hidden.
You gotta return the result. Console.log only writes things to the console, it doesn't actually send it to the test output
This comment has been hidden.
You're returning
"odd"
You missed " in Even
(Hidden)
nice!
This comment has been hidden.
This comment has been hidden.
I used ternary conditional operator to solve the problem, Wonderful!
nice
ikr
Hi! It might seems as a stupid question but whenever I try to submit my solution, I cannot. The Output window displays errors from the sample. The code works as I compiled it before and tried it. How should I go about properly publishing my solution?
What do the errors say?
This comment has been hidden.
The error is a result of the user modifying the initial solution stub.
Closing the question as obsolete, please post a new one if something still needs explaining.
Coffeescript, Javascript and Typescript should use
camalCase
Julia should use
snake_case
/snakecase
Fixed Coffeescript and Javascript.
Fixed Julia.
This comment has been hidden.
Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution and mark your post as having spoiler content next time.
You have the sample tests to play with, see which one your code fails, fix your code.
Thanks , I solved it
This comment has been hidden.
You have to return, and not print the string
yeah, thanks! I think I've just figured it out
Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution and mark your post as having spoiler content next time.
This comment has been hidden.
This comment has been hidden.
Your function should return the result instead of printing it,too. Mark your post as having spoiler content next time please.
This comment has been hidden.
This comment has been hidden.
Your oddness test is wrong, and gives false negatives.
Ahhhh, I realized now, because of negative numbers... Thanks!
When I run the Same code on other editors it runs perfectly. But here it shows an error.
This comment has been hidden.
You need to return your answer, not print it.
It would generally help if you mentioned which language you were having this problem with, and properly marked up your code. I'll give you the benefit of the doubt that you added the
Spoiler
tag yourself.Available documentation includes a troubleshooting guide, which includes those guidelines. ( It might or might not include the thing about
return
instead ofprint
. But I think it does. )My solution worked in my test, both here and in Visual Studio, but I get this error when I Attempt:
Test Failed Expected string length 3 but was 0. Strings differ at index 0. Expected: "Odd" But was: <string.Empty>
What am I suppossed to do? This site is quite confusing for begginers.
Please read the troubleshooting guide.
When you've read that, and still can't figure it out, please post a new question with a mention you followed said guide.
Closing.
Why can't I make use of "print" to output the results? The "print" is not highlightend by the IDE. What happened? By the way, the codes were done with Py3.
Since this is a function you have to return a value. Write return and then after write what you want to output.
oooops!I see. Many thanks!
is postgre don't know 'IF' statement like mysql? i can't use it here.
No, they're different, you can read about postgresql here: https://www.postgresqltutorial.com/
okay sir, thank you!
Hello. My code keeps failing one test here but works find in my shell. Any ideas? Thank you
Please refer to the troubleshooting guide.
If you've followed that and still can't figure it out, follow the guidelines also in there to post another question.
This comment has been hidden.
Please don't post solutions in Discourse.
my test works perfectly on jupyter notebook (working with python) but somehow i keep having errors on codewars
Not a kata issue, read this
No random tests.
Which language? At least Haskell, JavaScript do have them.
coffeescript, python, ruby added. Still missing for
Done for C++.
Done for C#.
Done for Clojure.
Done for Dart.
Done for Elixir.
Elm tests use Fuzz, which is a property-based testing framework. It runs tests 100 times, every time with a value generated randomly by one of four generators. Test output is quite terse, so test output panel might make an impression that there's not many random tests executed.
Done for Haskell.
Done for ObjectiveC.
Rust had the tests added some time ago.
Done for Shell.
PureScript has QuickCheck-generated random tests.
Random tests have been added to all languages. I'm closing this issue, please rise a new one if I happened to miss something.
Python tests are using
Test.expect
.Fixed.
why its showing EOF error? I run the same code on different IDE but it works there? Any explaination?
We do not get EOF error, so we do not know :(
My guess is that you are trying to read input from console, are you?
I had the same problem, I was getting the user to input data, but you can just a set number.
This comment has been hidden.
Don't post solutions here ! There's solutions tab for it. Also, use spoiler flag if you're gonna post code snippets.
So sorry! Literally noticed that right after I posted. But for some reaason, the solutions page wasn't unlocked, even after I solved the kata. Any help there? Sorry again!!
This comment has been hidden.
Check the last bullet point if this FAQ to get a hint on returning the answer instead of printing it.
You're not returning anything.
thank yu guys :)
уу
This comment has been hidden.
return, not print. In almost all katas, your function should return the result, use print only to debug your code, and the log will appear above the test result. Read this for some more info.
Thank you, bro. Helped a lot!
This comment has been hidden.
Hi
not a suggestion. don't post irrelevant content!
easy one
This comment has been hidden.
Hi VitaliKarpuk, in case you didn't know, it's forbidden to post code like that because everyone can see it on the dashboard (I have added the spoiler tag)
My code passes 6 of the tests, and all of the example tests. The test won't show me what it's passing that is failing; so I'm kinda stuck at this point.
print the inputs
This comment has been hidden.
Delete
print(
and)
ah...thank you!
I am trying to solve using Swift. Sample run works and I complete all the tests required but when I attempt something wrong..
This comment has been hidden.
Please:
This comment has been hidden.
Your functions should return in CW instead of printing the result, you should know that by now, don't you?
Figured it out, thanks)
Elm translation PureScript translation
Factor translation
Crystal translation R translation Reason translation
Bump.
Racket translation
Approved