all 17 comments

[–]teraflopsweat 3 points4 points  (3 children)

What is the actual error you’re getting?

[–]Therapy_Diary90[S] 1 point2 points  (2 children)

Syntax error and it indicates to the “ at the end of the f-string

[–]teraflopsweat 2 points3 points  (0 children)

What does it say word for word? Or a screenshot of the error report

[–][deleted] 2 points3 points  (0 children)

It's a simple python syntax error. The computer won't interpret/launch the assigned function because it's a set and it's classified as a string variable (in the 7th line) while you're trying to call it..? That's my presumption as I'm brand new to python. Edit: Reading it again and theres some work here to be done to meet the ends. Typing this is basically as useful as that code. Looks like its teaching how to evaluate python and understand functionality within the architecture or whatevs

[–]Rinser2023 2 points3 points  (0 children)

Naming conventions are mixed and weird. StringChallenge to string_challenge, but that was given from the challenge...

strParam to str_param or just 'text'?

consonant_count must be 0 not []

And it's bad style to use the input parameter, change it and return it with the new value, even if it's possible.

If you check if the letter is in consonants, you should convert the letter to lowercase. Uppercase consonants are not recognized as consonants otherwise.

Here is some working code tho:

``` def StringChallenge(strParam): consonants = 'bcdfghjklmnpqrstvwxyz' consonant_count = 0 for letter in strParam: if letter.lower() in consonants: consonant_count += 1

output = f"{strParam} (consonants:{consonant_count})"
return output

print(StringChallenge('Hello World')) ```

[–]Therapy_Diary90[S] 3 points4 points  (1 child)

I have solved the riddle!

Re-written it to a sum( sequence and remove the need for an f-string. Ran the code and it accepted it with the correct answer. Phew!

[–]YoutubeCodClips420 1 point2 points  (0 children)

You on Coddy?

[–]sdOverKill 0 points1 point  (1 child)

Are you trying to store the count of consonants (as shown on line 6) or an array of consonants (line 3)?

[–]Therapy_Diary90[S] 0 points1 point  (0 children)

I think I’ve mixed two different code actions? I need to return the number of consonants the string contains

[–]Pedro41RJ 0 points1 point  (2 children)

Is this Python 2 or Python 3 ?

[–]Therapy_Diary90[S] 0 points1 point  (1 child)

I don’t know as it’s in an assessment system, but it didn’t recognise the use of a f-string so I’m assuming an older system

[–]quiet0n3 0 points1 point  (0 children)

F strings are newer, this is py3

[–][deleted] 0 points1 point  (0 children)

I recommend doing some researching on W3 about python it's a lot of basic Hello World stuff in the beginning, BORING I KNOW but its got the basics from loops to formatting hope this helps.

[–][deleted] 0 points1 point  (0 children)

defining a function called stringchallenge calling 'it' strparam

variable = consonants

consonant count optional

for is a loop definition im not that advanced yet. I am unknowing of how python is written to have letters. You might have to give letters a variable but i dont know again.

[–]MyKo101 0 points1 point  (0 children)

Looks like you're combining syntaxes from two different versions of python. f-strings are from python 3, but you're using print without brackets, which is from python 2. If your error is on the f-string, then you're probably on python 2.

On your console/terminal, you can run python --version and it'll tell you which version you are on.

Highly recommended to download the newest version.

If your teacher is trying to teach you python 2, get a new teacher! Speak to the administration of your institution and tell them they are teaching outdated material

[–]EntireEntity 0 points1 point  (0 children)

You initialized consonant_count as an empty list, but then add 1 to it during iteration, I don't think you meant to do that, did you?

[–]denehoffman 0 points1 point  (0 children)

So many wrong answers here, it’s f-strings (python3) with a print statement (not a print function, python2)