Commit ·
4cb0548
1
Parent(s): 756547e
Create createaccount
Browse filesPython script to create a Signup and Login screen
- createaccount +32 -0
createaccount
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# First, we'll create a dictionary to store the users and their corresponding passwords
|
| 2 |
+
users = {}
|
| 3 |
+
|
| 4 |
+
# Now, we'll define a function to handle signup
|
| 5 |
+
def signup():
|
| 6 |
+
# Prompt the user to enter a username and password
|
| 7 |
+
username = input("Enter a username: ")
|
| 8 |
+
password = input("Enter a password: ")
|
| 9 |
+
# Add the username and password to the users dictionary
|
| 10 |
+
users[username] = password
|
| 11 |
+
print("Signup successful!")
|
| 12 |
+
|
| 13 |
+
# Next, we'll define a function to handle login
|
| 14 |
+
def login():
|
| 15 |
+
# Prompt the user to enter their username and password
|
| 16 |
+
username = input("Enter your username: ")
|
| 17 |
+
password = input("Enter your password: ")
|
| 18 |
+
# Check if the username and password match a set in the users dictionary
|
| 19 |
+
if (username in users) and (users[username] == password):
|
| 20 |
+
print("Login successful!")
|
| 21 |
+
else:
|
| 22 |
+
print("Invalid username or password. Please try again.")
|
| 23 |
+
|
| 24 |
+
# Now, we'll prompt the user to choose between signup and login
|
| 25 |
+
while True:
|
| 26 |
+
choice = input("Would you like to signup or login? (s/l) ")
|
| 27 |
+
if choice == 's':
|
| 28 |
+
signup()
|
| 29 |
+
elif choice == 'l':
|
| 30 |
+
login()
|
| 31 |
+
else:
|
| 32 |
+
print("Invalid choice. Please try again.")
|