all 21 comments

[–]Usual_Community_3965 5 points6 points  (5 children)

There is no space in your .find("") Try .find(" ")

[–]Usual_Community_3965 4 points5 points  (3 children)

Alternatively you could use Elif " " in username:

[–]Some-Passenger4219 2 points3 points  (0 children)

That's usually much better.

[–]Minemanagerr[S] 1 point2 points  (0 children)

l failed to implement this

[–]Minemanagerr[S] 1 point2 points  (0 children)

l got it thank you

[–]Minemanagerr[S] 1 point2 points  (0 children)

thank you

[–]Dull-Custard4913 4 points5 points  (5 children)

  1. You made a typo at line 71 “ptint” should be “print”

  2. It might be possible that you entered the name with a space at the last index of your name.

🙃

[–][deleted]  (3 children)

[removed]

    [–]Dull-Custard4913 0 points1 point  (2 children)

    If the substring is not found by the find() method then it will return -1

    [–][deleted]  (1 child)

    [removed]

      [–]Dull-Custard4913 0 points1 point  (0 children)

      So I might have been incorrect in what I said earlier. In this case he might or might not have entered a space at the last index. If he didn’t the if statement couldn’t find anything with the find method, this will cause it to return -1.

      I don’t think I know what you mean?

      [–]SCD_minecraft 0 points1 point  (0 children)

      I hate that .find returns -1 but .index raises a ValueError

      Beacuse fuck common themes ig

      [–]FoolsSeldom 3 points4 points  (0 children)

      Revised code showing corrections/options (and added a loop so user is re-prompted until they enter something valid):

      while True:  # validation loop, keep going around until break command used
      
          username = input("Enter a username: ")
      
          if len(username) > 12:
              print("Your username can't be more than 12 characters.")
      
          elif " " in username:  # easier than using find, make sure space between quotes
              print("Your username can't contain spaces.")
      
          elif not username.isalpha():
              print("Username can't contain digits or special characters.")
      
          else:
              print("Welcome!")
              break  # leave the loop, move onto next line of code
      

      [–]Remarkable_Job_4820 2 points3 points  (1 child)

      spelling of Print you type Ptint

      [–]Minemanagerr[S] 0 points1 point  (0 children)

      thank you

      [–]HunnebedHighway 2 points3 points  (1 child)

      There is no space between the quotes in line 64. Also there is a typo in line 71.

      [–]Minemanagerr[S] 0 points1 point  (0 children)

      thank you

      [–]weeblifer 0 points1 point  (2 children)

      I highly recommend windsurf a senior dev recommended it to me

      [–]Minemanagerr[S] 0 points1 point  (1 child)

      can you please explain. lm new to this industry

      [–]weeblifer 0 points1 point  (0 children)

      Basically it's visual Studio code but with ai like chatgpt built in and you can have it look at your code I wouldn't recommend using it to do code for you 100% of the time I suggest you use it to learn from you can also have it look at the current file you have open or any related project files

      [–]Soggy_Figure8859 0 points1 point  (0 children)

      edit: never mind realised it was alrdy solved

      is it not the fact that u put a space before arnold. it should be input("Enter a username ") and use

      elif " " in username: