'My code keeps reapting it self I don't how i will stop it so it can move on and do the other things i want it to do

So here is the code if run the begin function it will just run option1 and not print the other stuff like i want to make this login thing work but it won't work for some reseon.

def login():
    print ("You are now logged in")

def reg():
   file = open ("User_details","a")
   file.write("\n"+"Ussername"+","+"Password"+","+"Age"+","+"Real_name"+","+"Last_name"+","+"Email")
   file.close

def Access(option):
    if option == "login":
        input ("Ussername: ")
        input ("Password: ")
        input ("Age: ")
        input ("Real name: ")
        input ("Last name: ")
        input ("Email: ")
        login()
    else:
        print ("Enter all the info we will be asking you to register")
        input ("Ussername: ")
        input ("Password: ")
        input ("Age: ")
        input ("Real name: ")
        input ("Last name: ")
        input ("Email: ")
        reg()

def begin():
     
    print ("Hi my name is Steve would you like to register or login")
    option1 = input ("Login or Register: ")
    if option1 != "login" and "register": 
        begin()
    if option1 == "register":
        Access()
    if option1 == "login":
        login()
begin()
Access()


Solution 1:[1]

This is because your first conditional will always be True. For example, let's see how an example input would work:

>>> option1 = "unknown input"
>>> if option1 != "login" and "register": print("TRUE")
TRUE

# If we split the statement into pieces, we can see why
>>> option1 != "login"
True
# The part after the `and` isn't testing anything, and is always True!
>>> bool("register")
True
# Your `if` statement effectively tests option1 != "login"
>>> True and "register"
True

To fix this, you want to make sure that option1 isn't either of the strings. You probably want to clean up the input value a bit too, by stripping any whitespace.

option1 = input("Login or Register: ")
option1 = option1.strip()  # remove accidental whitespace from the ends

# The fixed `if` statement
if option1 != "login" and option1 != "register":
    begin()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 damon