簡體   English   中英

在巡回演出中使數字和字母有效和無效

[英]Making numbers and letters valid and invalid in turing

到目前為止,當您輸入字母時,我的數字是有效的,但是我不知道如何使數字有效。 我可以幫助您使數字和字母同時有效嗎?

var var_name : string

function check_letter (ch : string (1)) : int
    if ord (ch) >= 65 and ord (ch) <= 90 then
        result 1
    end if
    if ord (ch) >= 97 and ord (ch) <= 122 then
        result 1
    end if
    if  ord (ch) >= 0 and ord (ch) <= 9 then
        result 1
    end if
    result 0
end check_letter


put "please enter the postal code"
get var_name
for i : 1 .. length (var_name)
    if check_letter (var_name (i)) = 1 then
        put "postal code valid"
    else
        put "postal code invalid"
    end if
end for

(老實說,我仍然驚訝任何人仍在使用圖靈)

隨機數( 659097122 ),你在你的代碼是有字母在ASCII碼點。 數字0-9的碼點不是 0 - 9喜歡你有他們那里,他們可以找到一個ASCII表而不是: ASCII表

另外,為了使您的代碼更簡潔,您可以這樣做,而不是對代碼點進行硬編碼:

if ord(ch) >= ord('A') and ord(ch) <= ord('Z') then
...

暫無
暫無

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

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