by Anonymous » 07 Apr 2025, 06:52
Ich muss ein Bankprogramm in
Python erstellen und habe Schwierigkeiten, das Programm für Benutzernamen und Passwörter zu lesen, während ich nur von einer Zeile zur anderen liest. Ich würde es brauchen, damit nach dem Eingeben Ihres Benutzernamens und des Passworts die Textdatei, aber Zeile für Zeile, und nur den Benutzernamen und das Passwort erfasst, wenn sie beide in derselben Textzeile wären. < /P>
Code: Select all
accounts = {}
def login():
f = open("ANZData.txt", "a")
y = 0
count = 0
while y != 1:
print("whats your username? ")
loginuser = input()
print("whats your password? ")
loginpass = input()
print("whats your PIN ")
loginpass = input()
# Open the file in read mode
with open('ANZData.txt', 'r') as file:
# Read each line in the file
for line in file:
#CODE NEEDED HERE
def register(accounts):
print("what is your username?")
user = input("enter username:")
print("what is your Password? ")
passw = input("enter password: ")
print("please provide us a pin number to use")
PIN = input("enter PIN: ")
with open('ANZData.txt', 'a') as f:
f.write("name: " + user + " Password: " + passw + " PIN: " + PIN + '\n')
with open('ANZData.txt', 'r') as file:
for line in file:
key, value = line.strip().split(':', 1)
accounts[key.strip()] = value.strip()
print(accounts)
#Main code starts here:
#--------------------------------------------------------------------------------------------#
x=1
while x != 0:
print(accounts)
print("Would you like to login or register?")
logintoken = input("")
if logintoken == "enter":
registr = register(accounts)
elif logintoken == "login":
x=0
logi = login()
else:
print("try again")
x=1
while x != 0:
print(accounts)
print("\n Do you want to withdraw, deposit or check balance?")
decision = input("")
if decision.upper == "Balance":
print("placeholder")
< /code>
Ich habe versucht zu schreiben: < /p>
if loginuser and loginpass in file.readlines():
Dies würde jedoch zu Fehlern führen und ich weiß nicht, wohin ich sonst gehen soll.
Ich muss ein Bankprogramm in [url=viewtopic.php?t=11576]Python erstellen[/url] und habe Schwierigkeiten, das Programm für Benutzernamen und Passwörter zu lesen, während ich nur von einer Zeile zur anderen liest. Ich würde es brauchen, damit nach dem Eingeben Ihres Benutzernamens und des Passworts die Textdatei, aber Zeile für Zeile, und nur den Benutzernamen und das Passwort erfasst, wenn sie beide in derselben Textzeile wären. < /P>
[code]accounts = {}
def login():
f = open("ANZData.txt", "a")
y = 0
count = 0
while y != 1:
print("whats your username? ")
loginuser = input()
print("whats your password? ")
loginpass = input()
print("whats your PIN ")
loginpass = input()
# Open the file in read mode
with open('ANZData.txt', 'r') as file:
# Read each line in the file
for line in file:
#CODE NEEDED HERE
def register(accounts):
print("what is your username?")
user = input("enter username:")
print("what is your Password? ")
passw = input("enter password: ")
print("please provide us a pin number to use")
PIN = input("enter PIN: ")
with open('ANZData.txt', 'a') as f:
f.write("name: " + user + " Password: " + passw + " PIN: " + PIN + '\n')
with open('ANZData.txt', 'r') as file:
for line in file:
key, value = line.strip().split(':', 1)
accounts[key.strip()] = value.strip()
print(accounts)
#Main code starts here:
#--------------------------------------------------------------------------------------------#
x=1
while x != 0:
print(accounts)
print("Would you like to login or register?")
logintoken = input("")
if logintoken == "enter":
registr = register(accounts)
elif logintoken == "login":
x=0
logi = login()
else:
print("try again")
x=1
while x != 0:
print(accounts)
print("\n Do you want to withdraw, deposit or check balance?")
decision = input("")
if decision.upper == "Balance":
print("placeholder")
< /code>
Ich habe versucht zu schreiben: < /p>
if loginuser and loginpass in file.readlines():
[/code]
Dies würde jedoch zu Fehlern führen und ich weiß nicht, wohin ich sonst gehen soll.