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 (65) [earned 5 cycles]
View Answer
TheDrone7 (665)

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
  # the input does not have 4 characters/digits.
ArchieMaclean (687)

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

TheDrone7 (665)

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