Python Forum

Full Version: Working alongside a video, not getting the same result.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am working alongside a video for my class, and they have a code on screen that I put into Pycharm, and it is telling me the word is not defined. This is the code that isn't working:
if number < 11:
    print(1, 10)
    number = number + 1
It just keeps telling me "number is not defined" if that is the case, why is it working in the assignment video, but not for my Pycharm?
Quote:number = number + 1
The just redefines number because it uses whatever it was defined at before to add one to it and assigns it back to number again.
Quote:number + 1
With the code you shown, it never does define number in the first place. It should be before the if condition. The video might of already assumed you defined it.
number = 5
if number < 11:
    print(1, 10)
    number = number + 1

  1. Always show error traceback, unmodified and complete within error tags.
  2. Number must be defined before being accessed.
example:
This will create an error:
if number < 11:
    print(1, 10)
    number = number + 1
This will not:
number = 5
if number < 11:
    print(1, 10)
    number = number + 1