2 回答

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊
使用 while 循環(huán):
id1 = int(input("Enter 4-digit account pin: "))
id2 = int(input("Re-Enter 4-digit account pin for confirmation: "))
while id1 != id2:
id2 = int(input("Incorrect pin.. Please Re-enter: "))
id = id1
這會重復(fù)要求 PIN 確認(rèn),直到兩個(gè)值相等。

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
將整個(gè)事情包裹在一個(gè)while id1 != id2循環(huán)中。
# initialize to different values so the input loop will run at least once
id1 = 1
id2 = 2
# keep asking for both inputs until they are equal
while id1 != id2:
id1 = int(input(...))
id2 = int(input(...))
if id1 != id2:
print("Incorrect. Please re-enter")
# loop is done, so id1 is the same as id2
id = id1
添加回答
舉報(bào)