3
Checking that a user input has four digits
IsobelBolter (2)

how do you check that a user input has four digits?

You are viewing a single comment. View All
Answered by TimothyAnderso1 (55) [earned 5 cycles]
View Answer
2
TheDrone7 (510)

The best way would be similar to what Archie suggested, but first convert it to a string which would make the code look something like this

x = input ()
if len(str(x)) == 4:
  # the input has 4 characters/digits
else:
  # the input does not have 4 characters/digits.
1
ArchieMaclean (520)

@TheDrone7 When you get input it's already a string though.

1
TheDrone7 (510)

@ArchieMaclean They might take input as an integer or a list. Just to be safe converting it to a string would be better.