Steelingsword94
Steelingsword94

Reputation: 19

Python code [Code loops]

Hello am very new to python and ive atempted my first code like this but something seems to be wrong and one of the steps keeps looping. I am very confused on what to do so could someone please help me out.

Thank you!

import os
import time
def main():
    while True:
        print("Welcome To Amazon")
        search = input("Search.... ")

        if 'search == registration':
            reg()

        if 'search == login':
            login()

            #Must Register to continue
def reg():

    while True:
        print("Display Name")
        reg_user = input()
        print("Password")
        reg_pass = input()

def registered():
    time.sleep(1)
    print("Registration Successful!")

main()    
            #Must Login to continue

def login():

    while True:
        print("Enter Username: ")
        username = input()
        print("Enter Password: ")
        password = input()

    if 'username == reg_user' and 'password == reg_pass':
        time.sleep(1)
        print("Login Successful!")
        logged()

    else:
        print("Try Again!")


def logged():
    time.sleep(1)
    print("Welcome To CityRP Gaming")

main()

Upvotes: 0

Views: 28

Answers (1)

TheNodeMaster
TheNodeMaster

Reputation: 46

The while loop loops for as long as the condition is true. You used While True, and True will always be True. This means the loop will continue forever. To break out of a loop you can use 'break'.

Upvotes: 1

Related Questions