0

How do i tell the computer not to accept any digits less than 6 digits or any digits more 6 digits? I want user to enter 6 digit

print ("Enter your 6 main numbers") Main_numbers = input() I want to restrict the number of digits that can be entered to six digits not more or less , i don't know the code for that function, if the user enters 5 or 7 ,as long it's not 6 digits i want the computer to tell the user that ,they did not entered the required number of digits

11th Jun 2022, 10:07 PM
BRIAN NKOMO
8 Answers
+ 3
print ("Enter your 6 main numbers") while True: Main_numbers = input() if len(Main_numbers)!=6: print("Please enter 6 digits number only.") else: break The loop will continue to take the input until user enter 6 digits number.
12th Jun 2022, 2:03 AM
Pavan Barve
Pavan Barve - avatar
+ 5
You can check the string length of the the in out using the len() method and then make switch or if-else statements based on it.
11th Jun 2022, 10:08 PM
Justice
Justice - avatar
+ 3
Pavan Barve Rik Wittkopp Pls don't give finished code as answer. This is a learning app, and solving the problem for others defeats exactly that. Prefer giving hints to put the OP in the right direction. So (s)he finds the solution and learn for real.
13th Jun 2022, 3:29 AM
Emerson Prado
Emerson Prado - avatar
+ 3
Pavan Barve Kinda. What is some of a consensus is that the finished solution is a shortcut. The OP just sees the solution, doesn't have to think it. So it's way harder to grasp the logic, even more the steps to build it - which are the foundation of good programming. So yes, the finished solution teaches a little. But stops learning at this little.
13th Jun 2022, 2:15 PM
Emerson Prado
Emerson Prado - avatar
+ 3
Rik Wittkopp I understand. My point is that, even in that case, we have to help the OP in paving the way to find "how can (s)he do". It is a valid answer too, with the advantage you already understood. As a side note, we have to discourage the "give me the code" trend which is growing too much in SoloLearn. Everyone who asks or answer can help spread a learning culture.
13th Jun 2022, 2:20 PM
Emerson Prado
Emerson Prado - avatar
+ 2
Yes Emerson Prado , but don't you think knowing the answer is also a learning. Next time he or she will remember what needs to use exactly. No one remember the piece of code forever but the logic behind it.
13th Jun 2022, 3:46 AM
Pavan Barve
Pavan Barve - avatar
0
BRIAN BF SENERIO num = 123456 if len(str(num)) == 6: # your code goes here
11th Jun 2022, 11:51 PM
Rik Wittkopp
Rik Wittkopp - avatar
0
Emerson Prado I agree that providing a full answer to a coding challenge does not assist the learning process, but this question did not seem to fit that description. In my opinion, the OP was asking a "How can I do" question, not a "What is the answer to ...." question. Having said that, I welcome your concern as it is a valid point. 😁👍
13th Jun 2022, 8:11 AM
Rik Wittkopp
Rik Wittkopp - avatar