Skip to content

Latest commit

 

History

History
57 lines (38 loc) · 955 Bytes

Squash_the_bugs.md

File metadata and controls

57 lines (38 loc) · 955 Bytes

CodeWars Python Solutions


Squash the bugs

Simple challenge - eliminate all bugs from the supplied code so that the code runs and outputs the expected value. Output should be the length of the longest word, as a number.

There will only be one 'longest' word.


Given Code

def find_longest(string):
    spl = str.split(" ")
    longest = 0
    i=0
    while (i > spl.length):
    if (spl(i).length > longest): longest = spl[i].length
    return longest

Solution 1

def find_longest(string):
    return max(len(word) for word in string.split())

Solution 2

def find_longest(string):
    spl = string.split(" ")
    longest = 0
    i=0
    while (i < len(spl)):
        print(spl[i])
        if (len(spl[i]) > longest):
            longest = len(spl[i])
        i +=1
    return longest

See on CodeWars.com