Python Mastery Course: Debugging lesson syntax errors

Hi everyone,

I am a beginner going through the complete python mastery course and I am encountering a syntax error when I try to follow along with the debugging lesson (video 9 under functions).

I am currently using python 3.11.0 and VS Code version 1.73

the code I am copying from the lesson is:
image

and this is the error I have been getting:

Start
Traceback (most recent call last):
File “e:\Personal_Work\Coding\Python\app.py”, line 9, in
print(multiply(1, 2, 3))
^^^^^^^^^^^^^^^^^
File “e:\Personal_Work\Coding\Python\app.py”, line 4, in multiply
total *= numbers
TypeError: can’t multiply sequence by non-int of type ‘tuple’

[Done] exited with code=1 in 0.089 seconds

I am a little confused because the same code appears to work in the lesson. Is there something I am missing because this is a new version of python?

I did get it to return the proper value but only by changing line 3 from “number in numbers” to “numbers in numbers” but I do not now if this will cause me problems in the future while going through other lessons.

any insight on this will be appreciated,

Thanks!

Are you certain the file was saved when you got the error? I just checked and it definitely works with the syntax you have written out. It should not be getting that error if you use the code you have shown.

yes I am certain. Even when I type the code into a new file I get the same Type error message. Could it be a setting I might have accidentally switched on?

I also am getting these problems when trying to execute the code.

maybe it’s something wrong with my pylint plugin?

I see the bug now, can’t believe I missed it before:

total *= numbers

should be:

total *= number

And no, pylint is not the issue here.

ah yes it works now! thank you so much, I can’t believe I didn’t catch that simple mistake sooner.

1 Like

Tuples are immutable so thus causing this error

def multipy(*numbers):
    total = 1
    for number in numbers:
        total *= number
    return total

print("Start")
print(multipy(1, 2, 3))