There’s a conceptual error there. You’re asking for a password, a descriptive information, so it must be a string and not a number. You could even validate to only have numeric digits, but just because these are accepted characters should not use a numeric type. Numeric types are used to do math, not what you want there.
If you still insist on the error, if you are asking the person to enter the password and check if it is correct, then you do not need to check the size, if the person enters the password with wrong size the password is certainly wrong, the size is not relevant. If you enter the right password then the size will be right.
This would make sense if you were asking the person to enter a password that they would use from there, then you do a validation. Reinforcement that validation should not be so simple and that it should be like a string, but if you insist on the number and need to do a validation (in general password should accept everything) then it should be if the value is less than 10000, because it will certainly have 4 digits (9999) or less, which is strange, I’ve never seen a password be validated to be smaller than a size, in general validates if it has a minimum size, which once again shows how bad it is to use a number. But note that I’m only talking to completeza of reasoning, does not serve for this your code, it does not need to make this validation.
I didn’t even get into the merit of putting a password in the code, because I understand that this is circumstantial for an exercise that matters other things.
If the variable is of the whole type then if
(num < 10000)
the variable num has a maximum of 4 significant digits.– anonimo