-1

I'm very new to python and code in general and I'm wondering how i can do something like this:

User enters string, computer checks if string is longer then 10 characters and if it is it asks for the user to enter a new string. This is what i have right now.

usernamelength = (len(username))
if usernamelength > 10:
    return
else:
    print("Hello, %s. Placeholder text." %username)

Sorry if i'm missing out something obvious, as i said earlier I'm new to this. Any help appreciated :)

Rossilaz
  • 33
  • 1
  • 5

1 Answers1

0

This is a good place for a while loop instead of that if statement:

while usernamelength > 10:
      # ask for the username again
      # usernamelength = len(newUsername)

That way you'll just continue to prompt for the username until you're given something over 10 chars.

ethandjay
  • 61
  • 6
  • Sorry if i'm still missing something obvious, but It has worked a bit. It now always says that It's too long now though. Here's what i have now. ```username =input("Welcome! before we start, please enter your desired name.") usernamelength = (len(username)) while usernamelength > 10: username =input("Name too long. Please enter a name that is shorter then 10 characters.") else: print("Hello, %s. Placeholder text" % username) ``` – Rossilaz Nov 12 '19 at 23:48
  • Edit: solved :) Thanks! – Rossilaz Nov 12 '19 at 23:56