简体   繁体   English

通过输入用户验证号码

[英]Validate a number by taking a user input

I am new to programming and I wanted to write a code, and it turned out like this: (btw, bsn number is a registration number in my country and with this code I try to validate a random bsn number) 我是编程新手,我想写一个代码,结果是这样的:(btw,bsn号是我所在国家的注册号,使用此代码,我尝试验证一个随机的bsn号)

check_digits = [9, 8, 7, 6, 5, 4, 3, 2, -1]
bsn = input('Which bsn number do you want to check?')
total = 0

def has_valid_bsn_length(bsn):
    len(bsn) == 9
    if len(bsn) != 9:
        print('Not a valid bsn number')
    else:
        return bsn


def has_valid_check_digit(bsn):
    for i in range(0, 9):
        digit = int(bsn[i])
        result = digit * check_digits[i]
        total = result

if total % 11 ==0:
    print('Valid bsn')
else:
    print('Not a valid bsn number')

When I try this code, no answer appears. 当我尝试此代码时,没有答案出现。 Does any of you know how I can change the code so it works properly? 你们中有人知道如何更改代码以使其正常工作吗?

It seems to me you have a syntax error on line 6: len(bsn) == 9 Also you have to call your functions. 在我看来,您在第6行出现语法错误: len(bsn) == 9另外,您还必须调用函数。 As of now you have just defined them. 到目前为止,您已经定义了它们。 Add calls like that: result = has_valid_check_digit(bsn) 像这样添加呼叫: result = has_valid_check_digit(bsn)

And your second function does not return any value. 而且您的第二个函数不返回任何值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM