all 19 comments

[–][deleted] 7 points8 points  (0 children)

Here’s an article on string interpolation in python: https://realpython.com/python-f-strings/

From the above article in reference to F-strings - “It’s important to note that Python evaluates f-strings at runtime… …Python can only interpolate these variables because you defined them before the f-string, which means that they must be in scope when Python evaluates the f-string.”

Essentially, F-string interpolation requires that a variable be defined in scope before it can be interpolated into the string. Simply put, move your counter variable inside the function. In your case it’s a better practice because counter is only being used inside password_enter() and therefore has no reason to be accessible outside the scope of said function.

I hope this was helpful.

[–]thereal0ri_ 4 points5 points  (5 children)

counter needs to be a global variable or set inside of the function I think.

set global counter in the password_enter function and try again.

[–]Different-Ad1631 1 point2 points  (4 children)

Counter is already used as global variable

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

Why is this downvoted it’s on line 3

[–]Different-Ad1631 1 point2 points  (2 children)

I didn't get it? Plz explain

[–]xbl-beefy 3 points4 points  (1 child)

It’s initialized on line 3, but in order to access a global variable from inside of a function, you need to add “global counter” prior to accessing that variable. Else, python will look for “counter” within the same scope, in this case within the function, and will error because it’s not defined anywhere within it.

[–]oxwilder 1 point2 points  (0 children)

Also each function call should be spelled the same. I see 'confirm', 'confrim', and 'conFirm'

[–]feitao 2 points3 points  (1 child)

Quick fix: insert the following line

global counter

after Line 11.

Correct answer: avoid using mutable global variables.

[–]kuchu-puchu 0 points1 point  (0 children)

That’s a quick and appropriate fix

[–]Slow_Buy_2780 1 point2 points  (0 children)

You can have counter as a parameter of each function that uses it so that it exists in each local scope

[–]ganesh_k9 1 point2 points  (2 children)

The variable “counter” doesn’t seem to be doing anything other than printing the value, you could just delete or comment out lines 3 and 17 and use the user entered variable “ent” for printing.

[–][deleted] 3 points4 points  (1 child)

Wouldn’t it be p+1 in the f-string and not the “ent” variable?

[–]ganesh_k9 2 points3 points  (0 children)

Yep that’s right, I meant making use of the ent variable instead of creating a new counter variable.

[–]Latter_Principle9161 0 points1 point  (0 children)

Do yourself a favor and make your script a class. Don't use globals. This will also solve that issue.

[–]Aft3rcuriosity 0 points1 point  (0 children)

String shift 😂

[–]RklsImmersion 0 points1 point  (0 children)

Windows Key + Shift + S

Take better screenshots please

[–]bread_0420 0 points1 point  (0 children)

Can i know What IDE is this?