Input length validation#
One common requirement for passwords is that they be at least 8 characters long. In this challenge, you will first ask the user for a password with input()
. You will then implement user input validation using a while loop that checks if the provided password is at least 8 characters long. If not, the loop body asks the user to provide a different password, using input()
. This is repeated until the user gives a password that is long enough.
At the end of your program, print the valid password that the user gave.
Some notes on the sample Input in the tests:
For each sample input, there a couple lines of strings. Each of these strings represents a password that is supplied by the user once input is called.
The strings will be supplied in order.
For each test, each time that your program calls
input()
, it will read one of these strings, starting with the one on the first line. If it ends up callinginput()
again (asking the user to give a different password), then it will read in the string on the next line, and so forth.We have already added the initial call to
input()
below. You should implement your while loop below such that it prints the final accepted password.For testing purposes, do not provide any prompt strings to your
input()
calls.
For example with sample input 1:
The first time input is called, the test will provide “monday”.
Since the length of “monday” is only 6 characters long, your code should call input() again.
For this input call, the test will then provide “tuesday”.
Since the length of “tuesday” is only 7 characters long, your code should call input() again.
For this input call, the test will then provide “wednesday”.
Since “wednesday” is 9 characters long, it passes our requirement.
Print “wednesday”.
Sample Input 1:
monday
tuesday
wednesday
Sample Output 1:
wednesday
Sample Input 2:
apple
banana
pomegranate
pineapple
Sample Output 2:
pomegranate
Sample Input 3:
chocolate
vanilla
neopolitan
Sample Output 3:
chocolate
Sample Input 4:
doorknob
doorbell
doorhinge
Sample Output 4:
doorknob