-4
我對編碼非常陌生,所以這個問題可能非常愚蠢和明顯,但我應該在哪裏放置我的循環,以便StuL在每次向字典添加新密鑰時都不會重置,因爲每當我嘗試過時輸入迴路已經由用戶添加的按鍵保持復位我在哪裏可以在此代碼中實現一個while循環?
import time
StuL = {"1317281" : "Name : Reese John ID :1317281 DoB : 12/11/95 Address
: 57 Fake Road Phone Number : 02087475632 Gender : Male Tutor Group : 10K
Email : [email protected]"}
UserName = input ("Enter Username: ")
PassWord = input ("Enter Password: ")
if UserName == "MrLeeman" and PassWord == "hunter2":
time.sleep(1)
print ("Login successful")
time.sleep(1)
ch=(input("Enter your choice\n1:View student details\n2:Add
Students\n3:Exit"))
if ch == "1":
time.sleep(1)
inp = input("Enter student's ID number")
if inp in StuL:
time.sleep(1)
print(StuL[inp])
elif ch == "2":
time.sleep(1)
edit=input("Enter the ID for the student you wish to add")
inf=input("Enter the information for the student in the following
order\nName,ID,DoB,Address,Phone number,Gender,Tutor
Group,Email")
StuL[edit] = inf
elif ch == "3":
break
else:
print("Invalid option")
else:
print ("Password did not match")
請不要向我們提供代碼映像,以複製您的代碼的最喜歡的工具,並粘貼在這裏。 – Maroun
歡迎來到Stack Overflow! [請不要將您的代碼作爲圖像發佈。](// meta.stackoverflow.com/q/285551) –
除了發佈代碼,不包括代碼圖片,我發現很難猜測您正在嘗試做什麼 - 請更明確。如果你想修改一個循環,但不重置'StuL',確保你沒有在循環體中包含'StuL = {...}。 – tiwo