Python 3 Anaconda:Syntax Error on inexistent line#

  • Thread starter WWGD
  • Start date
  • #26
11,804
5,425
Wrong in what sense? It did what I designed it to do: After I enter an incorrect password 5 times, I get an error message and I am given access when I enter the correct one. In what way is it wrong? EDIT: I welcome input, I am a newbie after all, some 4 months' experience. I am just happy to have it run; it took me like 2 days to figure it out. But I will look into your comment; not sure what you mean it being a maintenance problem waiting to happen.
EDIT3: Thanks both for the input, will look it up.
Developers would shun this approach for the code maintenance issue it causes. You have the password text in two places.
 
  • Like
Likes WWGD
  • #27
1,428
1,264
Thanks, Wichik, program ran:
Happy to know about that. So there should be a problem with the interpreter on your PC. If restarting doesn't work, find out where the IDE stores temporary files and obliterate those files. This often solves the problem.
Problem with using different IDEs or other means is that I had installed both 2.x and 3.x with Anaconda on my PC.
Python 2.x has reached its end of life on January 1, 2020. You should forget 2.x and concentrate on 3.x only. Note that Python is not backwards compatible.

In addition, there are some points you should note:
  • Other members have already pointed out how you should be using if-elif-else. @Ibix has pointed out in post #17 what the better code is. But one thing that has not been pointed out is this: if you continue using elif instead of else, you will face serious trouble in recursion. Recursion is the process of a function calling itself repeatedly until a specified condition ("base case") is satisfied, after which the call ends. In recursion, you are needed to have a condition that will be executed when all other conditions are unsatisfied. Even though your program is logically correct to humans, the machine will want you to specify an else condition. Even if you are not using recursion now, it is a good habit to use else instead of replacing it by elif.

  • Do not put passwords into variables. That is highly unsafe. This approach might be okay for a beginner, but as time progresses, you will have to make your program safer. The better way is to store an encrypted form of the password into the variable. When the user enters the password, you encrypt tat using the same algorithm, and compare the encrypted forms rather than the unencrypted forms. Python has the cryptography package for this.
 
  • Like
Likes WWGD
  • #28
pbuk
Science Advisor
Gold Member
1,431
414
if you continue using elif instead of else, you will face serious trouble in recursion. Recursion is the process of a function calling itself repeatedly until a specified condition ("base case") is satisfied, after which the call ends. In recursion, you are needed to have a condition that will be executed when all other conditions are unsatisfied. Even though your program is logically correct to humans, the machine will want you to specify an else condition. Even if you are not using recursion now, it is a good habit to use else instead of replacing it by elif.
I'm not sure what you are trying to say here - there is no need to have an else clause and I don't see what this has to do with recursion. Actually many people would prefer this
Python:
def factorial(n):
    if n > 1:
        return n * factorial(n - 1)
    return 1
to this
Python:
def factorial(n):
    if n > 1:
        return n * factorial(n - 1)
    else:
        return 1
Do not put passwords into variables. That is highly unsafe. This approach might be okay for a beginner, but as time progresses, you will have to make your program safer. The better way is to store an encrypted form of the password into the variable. When the user enters the password, you encrypt tat using the same algorithm, and compare the encrypted forms rather than the unencrypted forms. Python has the cryptography package for this.
That's a good point, although I didn't know cryptography could do one-way hashing. I would use bcrypt or maybe scrypt.
 

Related Threads on Python 3 Anaconda:Syntax Error on inexistent line#

  • Last Post
Replies
9
Views
3K
  • Last Post
Replies
8
Views
3K
  • Last Post
Replies
7
Views
869
  • Last Post
Replies
3
Views
2K
Replies
6
Views
4K
  • Last Post
Replies
4
Views
2K
Replies
2
Views
9K
Replies
17
Views
1K
Replies
4
Views
814
Replies
18
Views
4K
Top