+ 1

can you debug this code

direct_sentence = " I love programming, said Jane.It us so much fun." direct_to_indirect(direct_sentence) print(indirect_sentence) def direct_to_indirect(direct_sentence): """ Convert direct speech to indirect speech """ words = direct_sentence.split() indirect_sentence = [] for i in range(len(words)): word = words[i] if word in ["said", "told", "asked"]: indirect_sentence.append(word) indirect_sentence.append("that") elif i == 0: indirect_sentence.append(word.capitalize()) elif word.endswith(".") or word.endswith("?") or word.endswith("!"): indirect_sentence.append(word[:-1]) indirect_sentence.append(word[-1]) else: indirect_sentence.append(worhd) return " ".join(indirect_sentence)

22nd Feb 2023, 10:30 AM
Damsara Welivita
Damsara Welivita - avatar
4 Respostas
+ 3
...here's your code, which now runs: direct_sentence = " I love programming, said Jane.It us so much fun." def direct_to_indirect(direct_sentence): words = direct_sentence.split() indirect_sentence = [] for i in range(len(words)): word = words[i] if word in ["said", "told", "asked"]: indirect_sentence.append(word) indirect_sentence.append("that") elif i == 0: indirect_sentence.append(word.capitalize()) elif word.endswith(".") or word.endswith("?") or word.endswith("!"): indirect_sentence.append(word[:-1]) indirect_sentence.append(word[-1]) else: indirect_sentence.append(word) return " ".join(indirect_sentence) print(direct_to_indirect(direct_sentence))
22nd Feb 2023, 11:06 AM
DavX
DavX - avatar
+ 2
Damsara, Where shall we start? Is this your full code? 1) LN 2 - Function call before definition. 2) LN 32 - Type 'worhd' not 'word'. 3) LN 3 - Printing 'indirect_sentence' before it's definition.
22nd Feb 2023, 11:01 AM
DavX
DavX - avatar
0
Always give information for those willing to help you. At least, what the code should do, and what it's doing wrong. Also, pls use Code Playground to show code. There, we can run your code, debug and test solutons. Finally, pls don't overuse line breaks. They make the code hard to read in small screens.
23rd Feb 2023, 1:15 AM
Emerson Prado
Emerson Prado - avatar
0
Nisha, no need to ask if you can ask … just ask away … ✌️
23rd Feb 2023, 4:35 PM
DavX
DavX - avatar