0

I'm currently making a game with a scoreboard that requires the user's name. If I were to make a programme that asks for the user's name, and if it is >20 chars, it would loop back and ask again

name_list = []

name = input('Please enter your name (not more than 20 chars): ')

while len(name) > 20:
    name = input('Please enter your name (not more than 20 chars): ')

if len(name) <= 20:
    name_list.append(name)

I'm wondering if there is a simpler way to do this

Kelven Lim
  • 73
  • 8
  • You don't need the `if` at the end. It only gets out of the loop if that condition is true. – Barmar Aug 08 '21 at 05:40
  • Here at Stack Overflow we fix non-working code. Code reviews of working code can be requested at [Code Review](https://codereview.stackexchange.com/). But usually the reviewed code is more complex that this. – Klaus D. Aug 08 '21 at 05:41

0 Answers0