0

Could someone debug the code, the output should be: Hello My name is Mark

text = 'HelloMyNameIsMark' # text is a string # using list comprehension to separate each word in text. modified_text = "".join( [letter if letter.islower() else " " + letter.lower() if letter in ['N','I'] else ' ' for letter in text] )[1:] print(modified_text)

9th Sep 2024, 7:11 PM
Aaron Paul
Aaron Paul - avatar
27 odpowiedzi
+ 4
Okay, fair. I assumed it was Python based on the fact that the OP (Original Poster) has taken a few Python courses. And I've been helping on this platform for years. I recognize a pattern. Although I don't believe we need to see the file extension or file type each time someone shows a line of code. I agree that properly adding tags that reflect the coding language is helpful.
10th Sep 2024, 7:57 PM
Chris Coder
Chris Coder - avatar
+ 5
Aaron Paul You almost had it right [letter if letter.islower() else " " + letter if letter in ['N', 'I'] else " " + letter for letter in text]
9th Sep 2024, 10:00 PM
Chris Coder
Chris Coder - avatar
+ 5
'list comprehension' in the tag would be a hint that it's Python.
10th Sep 2024, 11:47 PM
Bob_Li
Bob_Li - avatar
+ 4
Yash Thale it's called list comprehension. It is basically if-else statements written inside a list [ ] so you get a list of elements that conforms to those conditional expressions. https://www.w3schools.com/JUMP_LINK__&&__Python__&&__JUMP_LINK/python_lists_comprehension.asp
11th Sep 2024, 6:24 AM
Bob_Li
Bob_Li - avatar
+ 3
9th Sep 2024, 10:01 PM
Chris Coder
Chris Coder - avatar
+ 3
😁😁😁, yeah. Might have been Mojo.
10th Sep 2024, 11:51 PM
Bob_Li
Bob_Li - avatar
+ 2
you really don't need a list if you're going to join it to a string in the end. alternative form using generator expression instead of list comprehension and a simple string 'NI' instead of list ['N','I'] for the 'in' condtion. I also rearranged the condtions a bit: modified_text = ''.join((' '+x.lower() if x in 'NI' else ' '+x if x.isupper() else x for x in text))[1:]
10th Sep 2024, 1:28 AM
Bob_Li
Bob_Li - avatar
+ 2
Bob_Li that is not obvious enough. 🕵️‍♂️
10th Sep 2024, 11:50 PM
Chris Coder
Chris Coder - avatar
+ 2
Chris coder your code ran successfully, it'd been giving me headache.
10th Sep 2024, 11:54 PM
Aaron Paul
Aaron Paul - avatar
+ 2
Thanks Aaron Paul i'm happy to help.
11th Sep 2024, 12:02 AM
Chris Coder
Chris Coder - avatar
+ 2
Why is this discussion becomes a comment war?
11th Sep 2024, 2:35 PM
Celvien Kurniawan
Celvien Kurniawan - avatar
+ 1
What you posted can't be debugged cos it's not a code. I'll suggest you attach the actual code so it will be accessible
9th Sep 2024, 8:13 PM
RuntimeTerror
RuntimeTerror - avatar
+ 1
RuntimeTerror No, I'm not taking sides. I'm trying to defuse the animosity by adding a bit of lighthearted banter. You're correct in requesting for a definitive coding language in the tag. Wrong assumptions are a common pitfall, especially in coding. Chris Coder and I making the assumption that it's Python is perhaps a bit hasty, but the OP can correct us if we were wrong. The trouble with posting and written text is that the tone of the message is hard to convey. Misinterpretation of emotion is very common. What is supposed to be a lighthearted remark might be taken as a disparaging statement by the other party. So we end up with... this snowball.
11th Sep 2024, 12:13 AM
Bob_Li
Bob_Li - avatar
+ 1
Chris Coder and...you're rolling the snowball again 🫨
11th Sep 2024, 12:44 AM
Bob_Li
Bob_Li - avatar
+ 1
RuntimeTerror Syntax in coding is the set of rules that govern how to write valid code in a programming language. I didn't assume anything; I only said that to cheer you up, but unfortunately, it led to some inappropriate responses from you. I'll stick with being honest moving forward. I knew exactly what the code was and was able to help the OP. That is what I'm here for. In contrast, most of your comments have been largely irrelevant and mostly inaccurate. While I could spend all day educating you, it might come across as condescending at this point. Out of respect for you and the community, I'll keep my remaining comments to my self. Let's both try to have a better day ahead.
11th Sep 2024, 1:20 AM
Chris Coder
Chris Coder - avatar
+ 1
maybe the OP should mark this topic as closed...
11th Sep 2024, 1:23 AM
Bob_Li
Bob_Li - avatar
+ 1
👀 🍿
11th Sep 2024, 3:32 AM
[☢︎ᵣₐDᵢₒₐCₜᵢᵥₑ☢︎] - The Revenant Balor
[☢︎ᵣₐDᵢₒₐCₜᵢᵥₑ☢︎] - The Revenant Balor - avatar
0
Chris Coder to be fair, it's not a Python code if it's not in a .py or .cpy. it looks more of a Wikipedia pseudocode or the code I'm ask to write on paper during exams
10th Sep 2024, 7:07 AM
RuntimeTerror
RuntimeTerror - avatar
0
RuntimeTerror Python code remains Python code as long as it follows Python syntax and rules. If you are an experienced coder, you should be able to determine a coding language by its syntax
10th Sep 2024, 8:41 AM
Chris Coder
Chris Coder - avatar
0
I can name atleast 3 languages that use this syntax including ruby, groovy and gdscript. What makes Python code a Python code is not the syntax but the .py or .cpy filename which only the Python interpreter understand. Also many pseudocode uses this syntax, they're never Python and as a non-beginner, many pseudocode exists like this EXCEPT they are explicitly identified somewhere at the top as ".py, .cpp, .html" etc That's how the standard works not by assumption
10th Sep 2024, 11:03 AM
RuntimeTerror
RuntimeTerror - avatar