簡體   English   中英

如何獲得等於一定數量字符的輸入?

[英]How do I get an input to equal a certain amount of characters?

我們的老師告訴我們制作一個程序,以將郵政編碼驗證為北愛爾蘭的郵政編碼。 這意味着它必須包含字母“ BT”,並且必須等於8個字符。 在下面的代碼中,我設法使字母部分起作用。 但是,他沒有詳細說明如何使輸入等於8個字符。 他提到使用.length()和validation(嘗試和除外),但是我不確定如何使用.length()獲得8個字符。 這是我的代碼:

postcode = input("Please enter an Northern Ireland postcode:")
BT = "BT"
while BT not in postcode:
    postcode = input("That isn't a Northern Ireland postcode. Try again:")
print("This is a Northern Ireland postcode")

要獲取字符串中的字符數,可以使用len(postcode)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM