繁体   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