8 kyu
Returning Strings
77,760 of 243,290Aweson1
Loading description...
Strings
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.
This comment has been hidden.
This comment has been hidden.
You should not
print
the result butreturn
it.This is not a kata issue. See https://docs.codewars.com/training/training-example#writing-a-solution to find some help.
Thank you sir!
The comma should come after the person's name! The sentence should be
"Hello <name>, how are you doing today?"
instead of
"Hello, <name> how are you doing today?"
Hello test author, how are you doing today?
Too late to enforce such breaking changes across 28 languages with over 200K submissions
Agreed - the comma's in a weird position here. Not a problem in the grand scheme of things, but not the neatest.
This comment has been hidden.
Probably too late but, it looks like it might be the dollar sign and try putting a return statement at the beginning.
This comment has been hidden.
This comment has been hidden.
done
This took surprisingly long time to figure out.
This comment has been hidden.
Ok.
The description should be more explanatory, it seems like it asks for an input, when in fact there shouldn't be an input.
This comment has been hidden.
No kata reads the input that way, the functions use a param for that. This function could be called after you log in, and the value can be obtained from a database for example.
Your task here is not to create a script . Not every
.py
file is a Python script, and not every file with Python code is a Python script. Description explicitly says you should create a function, and functions usually are not interactive: they don't prompt for inputs, they don't present outputs.I might be wrong, but it seems like the comma is misplaced in this exercise. (For Rust instructions/tests. Also pointed out by @LucasZick.)
Nope as of now
im not sure the lua version is working properly
PHP tests are in wrong grammar, the comma is misplaced
It's as stated in the description.
that's why i said grammar, in correct grammar the comma would be after the name, like "Hello Lucas, how are you doing today?"
Yes, but it's not only in PHP, it's like that in all languages.
This comment has been hidden.
You're taking the instructions too literally, in:
"Hello, <name> how are you doing today?"
your code shouldn't return<name>
, that should be replaced with the value of the function's argument. So if you call your function like this:greet("trufo2")
it should return"Hello, trufo2 how are you doing today?"
This comment has been hidden.
Actual and expected are swapped in Kotlin
Fixed.
i tried to hard code this one i started using prompt() and since i work on vscode its working perfectly but the test wants us to code it differently , keep it simple and basic, and just return a value
I tried solving this using template literals where I use back ticks and ${}, but the tests say it fails. I'm new to coding so I may be wrong, but I feel there may be a flaw in the test.
I see my mistake: I didn't read carefully. 'function that "returns" a value.'
This comment has been hidden.
Hi there. It is asking to return a string value and not to print to the console. It is a small detail that I missed as well. Hope this helps
When I try my solution on replit, the result is exactly what is asked for but when I do it on here, it comes back as failed. Does anyone know why this could be happening?? I'm so confused!
Usually such things happen when your solution is incorrect. It is very difficult for us to tell why your solution is incorrect, because we do not know your solution.
Maybe this article will explain some things?
This comment has been hidden.
Read the description more carefully.
This comment has been hidden.
It is still function for the most parts
didn't remember to capitalize the h that was a tricky one thou
This comment has been hidden.
This comment has been hidden.
nice and simple. perfect for people just getting started.
Great for beginners (like me lol)
a nice and easy one :)
i sat ten minutes on this because i forgot to include doing. i was freaking out because it didnt work and then this.
That was nice trick, sometimes you donot need to think twice. 😅
This comment has been hidden.
You didn't fully understand the problem
You need to return, not display to the console/screen
so confusing.
and i got the symbol wrong too.
This comment has been hidden.
This comment has been hidden.
Why return? Well, its easier for kata creators to detect return, since they can just call the function.
I spent several hours trying to get persons name only, from the name column and accidentaly discovered that it wasn't necessary...
Dart translation
Approved
This comment has been hidden.
It's difficult to help without proper indentation... Write your code inside a code block:
```python
```
loved this very fun :D
How else do I assign a value to name without input, it won't let me return a value in input. in python
I've checked back in on your code, and
name
~ you can't do that if you want to pass the katabest of luck!
you can't actually use the
input()
function here or whatever it is in the language you're writing in. you have to indicate name as the placeholder name that they use in the example sentence. that really threw me off as the question requested for input.Thanks for this kata! Haven't used concatenation in SQL before
I never think did I will solve the 8 kyu while I am learning new coding language. :(
This comment has been hidden.
so easy I searched too hard ><
I thought the following code was the answer, but it's not. It passed during the initial test but failed 1 test case on the attempt. Maybe I need to take a break, but I can't see what's wrong with this.
select ('Hello, ', name , ' how are you doing today?') as greeting from person
Why didn't you have to specifically use the CONCATENATE statement within the select statement?
Make sure too look carefully on your code! I thought I was going crazy when I had a random period after the question mark.
Why do we need the library here?
good kata thanks for that
That's really a good practice for concatenation and also for basic function. I really like this problem.
This comment has been hidden.
Hi, and welcome to Codewars.
When you first open the kata, the "visible code" and "comments" (apart from the function name and definition) can be deleted - if there is a
pass
it is just saying that the function currently does not return anything.When you solve the kata, you can delete the
pass
statement - and replace it with areturn
statement.If you have a working solution in PyCharm, therefore, just replace your
print
statement with areturn
statement when you submit to Codewars test.Also you may find these docs useful:
https://docs.codewars.com/references/kata-trainer/
and
https://docs.codewars.com/getting-started/solving-kata
Best of luck on your Codewars journey!
Hello John, how are you doing?
not
Hello, John how are you doing?
Hello, I keep trying find out how to resolve this)
It would be nice if the instructions included something about how the function should behave if it's given a non-string input.
In which language does that happen?
it's just a presumption in real-life coding aspect but CW is not a real-life coding website, so closing!
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#.print-vs-return
print
returnsNone
, remove it.Thank you good sir. That was exactly the issue.
anyone know why it's not accepting f strings?? it's returning none for the var name in the script here, but when I run the exact same thing on my own computer, it returns the correct string as it should...
This comment has been hidden.
Hey guys, pretty new to java so I may have misunderstood the assignment here. I just spent a good hour trying to use a scanner/bufferedreader solve the issue, tried throwing exceptions or finding work around for the "no line found" error I was getting by filling in the input if the scanner received no input.
I gave up and came to see the solutions and realised this was totally unnecessary LOL. The "input" part of the question is a tad misleading to me.
Feel free to flame me if I am just stupid
This comment has been hidden.
Don't you see the difference? Assertion messages are explicit.
I am not quite sure about assertions. But probably the reason is in difference between "read" command and $1. I used "read" command which is the input from user in CLI, however during testing nobody makes input like that. Instead I need to use $1 which is the general first input parameter for running bash script. So with $1 it will be OK. Am I right with this understanding?
If really you don't see what's wrong with the assertion message, I just suggest you to read the description carefully again. Then look carefully at your code...
OP solved it, closing
try return instead of print
Please, the title is Returning Strings. Not a kata suggestion.
Thanks. Your hint helped a lot. I used 100s times "print" and was totally confused, as the output looked similar to the exercise... :-)
Muito bom esse kata
This comment has been hidden.
You are returning a
print
function.print
itself returnsNone
, so you are in effect, returningNone
. You can just get rid ofprint
.Thanks!
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting#expected-the-same
Thank you so much that was driving me crazy. Makes sense need to read the instructions more closely.
My method works perfectly fine, and outputs exactly what the test asks for, yet, it does not pass??
Your code works, not a kata issue.
This comment has been hidden.
A Java program needs a
main
function. This is where the code will start executing.The function in you've written for this Kata isn't a valid entry point.
To run your function in your IDE, add the function
public static void main(String[] args)
and use it to call your function.OP solved it, closing
The instructions should be rephrased. You actually don't need to get an input or call the function.
The input is passed through the argument, and where do you see you should call the function yourself?
That's because, as a beginner, I've that you should call the function you created in order to get the return.
Your function is called by the tests, read this: https://docs.codewars.com/getting-started/solving-kata to get how Codewars works.
It's the same thing for every katas: you need to write a function that solves the task, tests call your function and check it does the job correctly. If you are not familiar with how Codewars works, you should have a look at the documentation (Chrono79 gave you the link). However, not a kata suggestion.
Thank you both of you. I'll definitely have a look. Already learned a lot here.
While it's not necessary to complete the kata, I have no idea as to what 'throw' and therefore 'throw new' does. I feel like I have reasonable knowledge of try catch structures but 'throw' has always evaded me. I've looked online but all the explanations tend to be vague or beyond my understanding. Could someone please help me out with this?
(Offtopic answer deleted)
You can always ask for help on
#csharp
channel of Codewars Discord. Someone there will definitely be willing to explain.Throw just causes an exception to appear, for an example
will send an exception of NotImplementedException with the description "Greet is not implemented"
The test says my code passed, but when I run the attempt it says it fails and the expected code is a weird random string.
Ex: expected: <Hello, [yzFhtxLFRAzgiFIBKUTROwmSXXT] how are you doing t...>
Wtf is happening? lol
Your code is wrong, not a kata issue.
yzFhtxLFRAzgiFIBKUTROwmSXXT was the name passed into it, it doesn't use real names because that would take too much effort for nothing.
Look at the actual, and figure out what your code is doing wrong.
This comment has been hidden.
harsh comment ;-) approved
This comment has been hidden.
Kata solution != kata suggestion
This comment has been hidden.
approved
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Without the **
Test it: Error comes in Attempt: Passed
???
No language, incomplete logs, we cannot help. Come with more solid informations, see there: https://docs.codewars.com/training/troubleshooting/
"Make a function that will return a greeting statement that uses an input"
Doesn't use an input. Stupid misleading, confusing description
Exactly! Copied into Python IDLE and tested it there after confirming from docs that I was using input correctly. Finally chose to see the solution and was baffled at how any of those are correct since there's no user input! So I wrote correct code, but couldn't get it to pass. Maybe I'm just stupid since most everyone else seems to have gotten it. I hope this is the exception rather than the rule on this site...
What happened with me was the same problem described below. My query is correct. Is the same result comparing with expeted result, but when I attemped appears a message saying 'person table has name data' Can you guys fix this?
You need to post your code in spoiler flag or else we cant help u ~~
This comment has been hidden.
This comment has been hidden.
9kyu hehe
Coffeescript translation
Several people have logged issues concerning the SQL description. And to be honest "has name data" -> this part is not clear at all.
This comment from one of the solutions sums it up nicely.
I suggest to take over those last two lines in the description.
Changed kata description making it language dependant.
Did Go break?:
Oh boy, I just noticed in Go "Hello" is expected, not "hello" (in fact, all languages seem to expect "Hello"). I got confused somehow.
Julia translation
The table name is
person
. in SQL task you should just select data from this table (only one column with the namegreeting
). IT WAS UNCLEARWhat's unclear about this?
Comment in the initial code:
From the kata description:
I'm able to pass the test with no errors, my outcome looks exactly as it should, but when I attempt I get this error:
There was an error with the SQL query: PG::DuplicateFunction: ERROR: function "hellothere" already exists with same argument types
Any help or ideas on what could it be causing it?
Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Note: in SQL you should make a
SELECT
, not a function. Instructions are unclear about that.Thanks a lot, that solved for me :) I simply used the select statement I was using to create my function ... Yes the fact that the instructions say: "Make a function" made me create one ... not super clear lol
use
create or replace function
instead ofcreate function
This is pointless. Sorry.
Very poor instructions and even if the query is correct it does not solve the problem.
What is the name of a table in SQL part?
From initial code:
Clojure translation
https://www.codewars.com/kumite/5fb53029fea4530022310f9f?sel=5fb53029fea4530022310f9f
This comment has been hidden.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#when-i-print-my-answer-it-looks-exactly-the-same-as-the-expected-output-yet-tests-fail the last bullet point.
Thanks!
No problem.
Thank you for this.
Howdy!
Please explain why didn't work, Failed:
should have 10 rows Test Failed expected: 10 got: 1
(compared using ==) should return the expected results Test Failed @@ ,greeting +++,"Hello, Coy Steuber how are you doing today?" +++,"Hello, Edythe Vandervort how are you doing today?" +++,"Hello, Mrs. Loraine Murazik how are you doing today?" +++,"Hello, Miss Marge Jacobi how are you doing today?" +++,"Hello, Delbert Torp how are you doing today?" +++,"Hello, Miss Selmer Koelpin how are you doing today?" +++,"Hello, Eriberto Bailey DDS how are you doing today?" +++,"Hello, Dwight Kuhn how are you doing today?" +++,"Hello, Jarrell Friesen how are you doing today?" +++,"Hello, Adah Bauch how are you doing today?" ---,"Hello, test how are you doing today?"
OP solved it, closing
For beginners this is very terrible exercise - no table name. Next time please either make better descriptions or stop making Katas altogether.
The table name is person.
That's the initial code for SQL. The kata description is shared amongst all languages, there can be language dependant code blocks too, but the info is already there, so...
Hi! Could you translate this kata into beginners language, for me, please
I have no idea what to do
me too bro, me too.
what does it mean? this? import sqlite3
That's a note for people doing SQL version, you've done Python so far, so you can ignore it.
This comment has been hidden.
Not a suggestion, rather a question. RETURN the result (as the name implies), not print it (this applies to all katas).
why wouldn't it work with return 0? and cout?
That's not how it works around here. The tests compare values that are returned, and not from output stream. You can look at some test cases on bottom right.
Go translation
This comment has been hidden.
It doesn't happen to me, try clicking reset. BTW your solution is marked as invalid.
Yes thats what I am saying it let me pass the kata with a solution that is now classed as invaild.
Both pass the sample tests, but it doesn't work when clicking attempt, maybe you had a cached version. Note the SQL translation was modified last week.
In SQL the table name is person.
Yes, that's what the comment in the initial code says
Description says:
"Hello, <name> how are you doing today?"
but SQL tests expected (other languages seem ok):
"Hello <name>, how are you doing today?"
Fixed.
A pretty basic excercise, but very helpful for beginners!
that task have a bug
What bug
uhh iam just 8 kyu and iam pretty new to coding but this thing is showing the same thing i got Log 'Hello, Ryan how are you doing today?' None should equal 'Hello, Ryan how are you doing today?'
replace
print
withreturn
SQL translation
Can this translation be reviewed for approval?
'alr approved some time ago'
R translation added. Please review and take care :).
Lua Translation
Thanks for task!
This comment has been hidden.
Java translation ready https://www.codewars.com/kumite/5f2f1e97542ae3000f99f275?sel=5f2f1e97542ae3000f99f275
Approved ~~
TypeScript translation is ready! Please check and approve.
@below should be issue. Agreed, should be
Hello name, how are you doing today?
That's definitely not an issue.
NOTE: The correct use of comma in English is "Hello Name, how are you?".
If we're going to engage in pedantry, the correct use would be "Hello, Name. How are you?" :)
оо
String interpolation doesn't work in this kata. I put ${name} in the middle. It didn't work out. (Javascript)
Don't know what you're talking about, it works, are you using backticks or quotes? You can check my solution with View Solution if you don't believe me.
Didn't work for me either but worked on codepen. Other solutions use it though, weird!
probably doesnt know how to use it or used wrong type of quotes
Use `1 ${interpolated} 2`.
Those are backticks (`), not quotes (').
This comment has been hidden.
Not a suggesion.
You're not allowed to leave solutions in comments.
Haskell translation (first one) : https://www.codewars.com/kumite/5b51fa6ebdd074471b00017c?sel=5b51fa6ebdd074471b00017c
PHP translation, please check and approve :-)
This comment has been hidden.
Python, Ruby, Crystal and c++ translations kumited, cheers :)
I am concerned that your translations only have 40 random tests contrary to the original's 100. Also the link that says Python is actually JS
You are right on the language, I would not be too concerned about doing too many tests for an 8kyu kata: CW has certainly better uses for their computing power.
To be honest, there are many other katas like this one already out there.
Add more tests. Include random tests with special characters as well.
Added random test.
You need more sets.
Added.
Not enough tests and no testing for other type of inputs.
Added more tests. Since this is a simple kata, I have left it so that only strings are passed.
I made the correct function but it keeps telling me I did it wrong
Not an issue. Plus, it seems you solved it in the end.
yeah, try doing it in nasm and check how easy it is
Should really have more than two tests, even for simple problems.
The test should be: Test.assert_equals(greet("Ryan"),"Hello, Ryan how are you doing today?")
I changed it.
The example test case is broken, and fails to compile!
For me the test case compiles fine when I try it so, I will try and look into it further.