Week 2
Solutions to Python Basics - Conditional Logic and Input
Exercise 1 - Login System
# Store the name and password in 2 separate variables
name = "Alex"
password = "1234"
# First get the user to enter their name
input_name = input("Enter your username: ")
# Check against the name we have stored in 'name'
if input_name != name:
# The input_name does not equal the name
print("You have entered an incorrect username")
else:
# The input_name matches the name -> ask for password
input_password = input("Enter your password")
if input_password == password:
# Password is correct -> print a secret message
print("this is a secret")
else:
# Password didn't match -> print an error
print("You have entered an incorrect password")Extension Exercise 1 - Case Sensitivity
Extension Exercise 2 - Two users
Extension 3 - Bad Passwords
Last updated