[請益] APP 註冊用戶姓名重複

看板MacDev作者 (沉睡在墓地裡的Classical)時間9月前 (2023/07/30 15:04), 9月前編輯推噓1(106)
留言7則, 3人參與, 9月前最新討論串1/1
我在編寫一個名為**ve**e* App的程序 應用程序用於管理用戶信息 每個用戶都有一個唯一的用戶ID和姓名 用戶可以登錄、註冊和修改個人信息 我已完成並進行一些測試 然後在最後的測試中,我發現一個問題 當用戶嘗試修改姓名時,有時會發生姓名重複的情況 即兩個不同的用戶的姓名,變成了相同的 現在產生問題是 有時候可以正確檢測到重複,有時候就會漏掉 是否我函數部份搞錯(? 還是..... 新手努力摸索還在寫碼測試~請多包涵 ******e* App def __init__(self): self.users = {} def register_user(self, user_id, name): if user_id in self.users: print("User ID already exists. Please register with a different ID .") else: self.users[user_id] = name print(f"User {user_id} registered successfully with the name {name }.") def login_user(self, user_id): if user_id in self.users: print(f"Welcome! User {user_id} is logged in with the name {self.u sers[user_id]}.") else: print("User ID does not exist. Please register as a new user.") def modify_name(self, user_id, new_name): if user_id in self.users: current_name = self.users[user_id] if current_name == new_name: print("New name is the same as the current name. Please enter a different name.") else: for _, name in self.users.items(): if name == new_name: print("Name already exists. Please enter a different n ame.") break else: self.users[user_id] = new_name print(f"User {user_id}'s name has been modified to {new_na me}.") else: print("User ID does not exist. Please register as a new user.") if __name__ == "__main__": app = VeeApp() app.register_user("001", "Rosa") app.register_user("002", "Calii") app.login_user("001") app.login_user("003") app.modify_name("001", "Calii") app.modify_name("002", "Rosa") -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.72.2.145 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1690700652.A.D59.html ※ 編輯: cici950630 (42.72.2.145 臺灣), 07/30/2023 15:14:15

07/30 16:37, 9月前 , 1F
你在做更新時有用user id 作為唯一識別
07/30 16:37, 1F

07/30 16:38, 9月前 , 2F
嗎?
07/30 16:38, 2F

07/30 16:43, 9月前 , 3F
資訊太少了 看不出是畫面上重複還是
07/30 16:43, 3F

07/30 16:44, 9月前 , 4F
資料真的重複 是app資料還是後端資
07/30 16:44, 4F

07/30 16:44, 9月前 , 5F
07/30 16:44, 5F

07/30 16:45, 9月前 , 6F
沒程式碼就是要別人通靈而已
07/30 16:45, 6F

07/30 17:55, 9月前 , 7F
謝謝,我好像弄有點懂了
07/30 17:55, 7F
※ 編輯: cici950630 (42.72.2.145 臺灣), 07/30/2023 17:57:16
文章代碼(AID): #1anWjirP (MacDev)
文章代碼(AID): #1anWjirP (MacDev)