What's wrong with my python code?

What’s wrong with my code?

I assume this is an obvious and basic solution but I’m just beginning to learn, I’ve got no idea and can’t find an answer in my previous lessons.

Repl link:

The problem is on line 12 (below. score and max are both previous input values, the main py isn’t detecting any grammar issues but the console can’t get past it.

Thanks in advance!

If you read the error message it says there is a string and it expected an int. This is because score is still a string.
This means line 12 is trying to do int(string/int) that is not possible.

3 Likes

Hey @Renegon! Welcome to the community!

Since this is a help on a course, we won’t exactly give the direct answer, but we can guide you along the right path.

When your program is running that line of code, it’s running it like this:

final_percentage = int('42' / 69) # ==> final_percentage = int(score / max)

Since Python is a strongly-typed language, it will produce a TypeError.

Try finding a way to turn score into an integer.

2 Likes

I wouldn’t say strongly typed, it is actually known for its loose typing. In “strongly typed” languages, getting into a situation like this is almost impossible with a decent knowledge of types.

3 Likes

I guess so, since you don’t need to state the type of the variable, but it’s not like languages like Javascript, where it turns the value into a suitable type to do the operation, which I originally meant.

Well JS is a mess and what you describe causes bad habits. But hey I dislike JS and by now this is known.
Python is dynamically typed but at least it does give errors like this as such a thing should never be allowed.

1 Like

I don’t have an opinion with Javascript (or any language in general). So long as I am able to understand and gets the job done, I’m alright with it.

But I will say that the errors are useful, because it makes programmers more consistent with their types, and like what you said, avoid bad habits.