Objective
Develop a Python program that prompts the user to enter their login and password (both must be integer numbers) and repeats the prompt as many times as necessary until the entered login is "12" and the password is "1234".
Example Python Exercise
Show Python Code
# Initialize the correct login and password
correct_login = 12
correct_password = 1234
# Use a while loop to prompt the user for login and password until they are correct
while True:
# Prompt the user to enter their login
login = int(input("Please enter your login: "))
# Prompt the user to enter their password
password = int(input("Please enter your password: "))
# Check if the entered login and password are correct
if login == correct_login and password == correct_password:
print("Access granted")
break
else:
print("Incorrect login or password. Please try again.")
Output
Case 1:
Please enter your login: 12 Please enter your password: 1234
Access granted
Case 2:
Please enter your login: 11 Please enter your password: 123 Incorrect login or password. Please try again.
Share this Python Exercise
Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.
In this exercise, you will develop a Python program that prompts the user for their login and password, both of which must be integers. The progr...
In this exercise, you will develop a Python program that prompts the user for two numbers and displays their division and remainder. If 0 is entered as ...
In this exercise, you will develop a Python program that displays multiplication tables from 2 to 6 using nested "while" loops. The program will iterate throug...
In this exercise, you will develop a Python program that prompts the user to enter a number and a width, and then displays a square of that width using ...
In this exercise, you will develop a Python program that writes the even numbers from 10 to 20, both inclusive, except 16. The program will implement three different methods...
In this Python exercise, you will develop a program that prompts the user to input a number, width, and height and displays a rectangle of the specified...