+ 4

How can I solve python code couch longest word

21st Dec 2020, 7:10 AM
Omkaar
Omkaar - avatar
16 Answers
+ 7
Just a Hint: You can use string method ".split()" to have a list which contain each word of the sentence each element. You can also use the string method "len" to find how many letters are in a word. And if you encounter an error in your code, just show your attempt here and we may help you fix it. Good Luck!
21st Dec 2020, 7:42 AM
noteve
noteve - avatar
+ 6
Omkaar , just give an addition hint to what 《 Nicko12 》 mentioned: - split input sentence to a list using split() - use a for loop to iterate over that list of words, and check each word for the length. <<<---- - find the longest word
21st Dec 2020, 11:49 AM
Lothar
Lothar - avatar
+ 6
yes. code couch
23rd Dec 2020, 5:46 PM
Galaxy-Coding (inactive)
Galaxy-Coding (inactive) - avatar
+ 3
Thank you guys
21st Dec 2020, 12:34 PM
Omkaar
Omkaar - avatar
+ 3
I have done it
21st Dec 2020, 1:00 PM
Omkaar
Omkaar - avatar
+ 2
You should take the input since it is a challenge, cause challenge has different test cases which means different inputs Here is how to take input values x = int(input()) y = int(input()) print(x + y) - - - - - - - - - - - - - - We used "int" to declare input values as an integer because "input()" takes values as string as default. And we need it to be an integer so that we can add it so we need it to be " int(input()) ". Then assign the input value to a variable, here in the code above the variables are x and y. (x holds/stores first input value and y holds/stores the second value.) Then lastly we print the output or the sum of our two variables. " print(x + y) "
21st Dec 2020, 12:43 PM
noteve
noteve - avatar
+ 2
Yeah it is actually hidden and cannot be seen. Imagine if a solver can see all input values, then he/she will just print the expected output, right? So the purpose of it having hidden test cases is so that a solver will create a code/pattern/algorithm that satisfies whatever the input may there be. Dont worry input will be taken even though these test cases are hidden, just read the instruction of the problem of what the input may look like.
21st Dec 2020, 12:48 PM
noteve
noteve - avatar
+ 2
Thank you brother you are best
21st Dec 2020, 1:00 PM
Omkaar
Omkaar - avatar
+ 1
Alright, show your code attempt so far.
21st Dec 2020, 12:37 PM
noteve
noteve - avatar
+ 1
But in code coach input box in which write don't come. And how can I solve two test cases
21st Dec 2020, 12:45 PM
Omkaar
Omkaar - avatar
+ 1
First, read and anlalyze the challenge's/problem's instruction carefully. It is written their what should be done, what should be the input, and what should be the output. Then, another way. Look at the first 2 cases and observe what kind of input is there, For Example for test case 1: Input: 2 4 - - - - - - - - - - - - - - Then you now have a clue here, that you need to take input of two integers which will look like this on your code. x = int(input()) y = int(input()) #Then some code that will satisfy the expected output - - - - - - - - - - - - - - - - Remember that in challenges input block, every line means new input variable. For example It has 3 lines of input Input: 1 2 3 - - - - - - - - - - - - - - - Then you need Three(3) variables to hold this inputs. x = int(input()) y = int(input()) z = int(input()) #Then some code that will satisfy the expected output
21st Dec 2020, 12:54 PM
noteve
noteve - avatar
0
I am having problem in one more "Simple calculator" I cannot get the answer can you please helps me.
21st Dec 2020, 12:36 PM
Omkaar
Omkaar - avatar
0
# your code goes here x=5 y=4 a=22 b=11 print(x+y) print(a+b)
21st Dec 2020, 12:37 PM
Omkaar
Omkaar - avatar
0
So how can I solve them
21st Dec 2020, 12:50 PM
Omkaar
Omkaar - avatar
0
My one line code: print(max(input().split(), key = len))
19th Jan 2021, 1:57 PM
Rajneesh Kumar Singh
- 3
Hi
22nd Dec 2020, 10:35 AM
Upreti upяєтi