この質問に対する答えが明らかである場合は申し訳ありませんが、私は Python を初めて使用します (今朝、C との構造の違いやその他の事柄に関する小さなドキュメントを読み始めたばかりです)。練習中にATMを作ることにしました。ただし、検証プロセスで何か奇妙なことが起こりpassword
ました。ユーザー データベースを表す .txt ファイル内のパスワードと入力を比較するところです。2 つの文字列が完全に等しいにもかかわらず (そして、はい、型を確認しました。どちらも ですclass str
)、私のスクリプトは 2 つを正しく比較できません! 私は探していますが、明らかな何かが欠けていると確信していますが、それを見つけることができません。
関連するビットは次のとおりです。
class MockUserInterface:
def __init__(self):
ccn = input('Enter your Credit Card Number --> ')
password = input('Enter the corresponding password --> ')
self.db = MockDatabase()
self.processUser(ccn, password)
processUser(self, ccn, password)
ccn とパスワードを VerifyUser に渡してFalse|dictionary
値を取得します...
class MockDatabase:
def __init__(self):
self.initdata = open('D:/users.txt', 'r')
self.data = {}
line = 0
for user in self.initdata:
line += 1
splitted_line = user.split(',')
self.data[splitted_line[0]] = {'Name' : splitted_line[1], 'Password' : splitted_line[2], 'Balance' : splitted_line[3], 'id' : line}
self.initdata.close()
def verifyUser(self, ccn, password):
if ccn in self.data:
if ccn == self.data[ccn]['Password']:
return self.data[ccn]
else:
print(password, self.data[ccn]['Password'])
else:
print(self.data)
users.txt は次のようになります。
13376669999,Jack Farenheight,sh11gl3myd1ggl3d4ggl3,90001
10419949001,Sardin Morkin,5h1s1s2w31rd,90102
12345678900,Johnathan Paul,w3ll0fh1sm4j3sty,91235
85423472912,Jacob Shlomi,s3ndm35h3b11m8,-431
59283247532,Anon Tony,r34lp0l1t1k,-9999
スクリプトを実行すると、出力は次のようになります。
C:\Python33\python.exe D:/PythonProjects/ATM(caspomat).py
Enter your Credit Card Number --> 13376669999
Enter the corresponding password --> sh11gl3myd1ggl3d4ggl3
sh11gl3myd1ggl3d4ggl3 sh11gl3myd1ggl3d4ggl3
Process finished with exit code 0
繰り返しますが、答えが明らかであるか、十分な情報を提供していない場合は申し訳ありません!