How do I get the program to give the user another chance after entering the incorrect detail?

Instead of giving the user 3 chances it just prints access denied 3 times but I am not sure how to change the code so that it would give the user 3 chances and also it prints welcome even if the user enters the incorrect details so I would be grateful if someone could help me with this

Tbh i am a very novice programmer so I was not expecting it to work but if it did work i would have expected it to give the user 3 chances and if they get all the chances wrong then it would print something along the lines of “Account locked out”

username = "Student1"
password = "WatfordLenMein"
input1 = input("Enter username: ")
input2 = input("Enter password: ")
for i in range(3):
    if username == input1 and password == input2:
        break
    else:
        print("Access denied")
print("Welcome")

1

Your code should rather look like this:

username = "Student1"
password = "WatfordLenMein"

is_login_successful = False

for i in range(3):
    # ask the user to enter login/password on every iteration of the loop.
    # if you keep this outside, then the user will be prompted to enter
    # credentials only once .. which is not what you want.
    input1 = input("Enter username: ")
    input2 = input("Enter password: ")

    # if the login/password match, then the loop is over
    if username == input1 and password == input2:
        is_login_successful = True
        break
    else:
        print("Access denied")

# as suggested by kuro, the use of a flag simplifies the overall logic
if (not is_login_successful):
    print("Account locked out")
    exit(1)

print("Welcome")
...

As “kuro” mentioned you have to put the input() function inside the for-loop to check three times if the input is correct:

username = "Student1"
password = "WatfordLenMein"

for i in range(3):

    input1 = input("Enter username: ")
    input2 = input("Enter password: ")

    if username == input1 and password == input2:
        print("Welcome")
        break
    else:
        print("Access denied")

You need the inputs to be inside the for loop. This is also a good use-case for the for/else construct.

username = "Student1"
password = "WatfordLenMein"

for _ in range(3):
    u = input("Enter username: ")
    p = input("Enter password: ")
    if u == username and p == password:
        print("Welcome")
        break
else:
    # This will be executed if the for loop terminates due to range exhaustion - i.e., no break
    print("Access denied")

The only problem with this is that once you’re outside the loop you don’t know if you got there with a valid username/password or you had too many retries but that’s outside of the scope of your question

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật