Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8954951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:25:51+00:00 2026-06-15T14:25:51+00:00

this is my current code: while True: try: username = input(Username: ) if len(username)

  • 0

this is my current code:

while True:
    try:
        username = input("Username: ")


        if len(username) < 8:
            print ("Sorry, the username must be at least 8 characters long.")


        if username.isalnum() == False:
            print ("Sorry, your name can only contain alpha numeric characters")


        numupper = 0


        for c in username:

            if c.isupper() == True:
                numupper += 1

            if numupper > 0:
                print ("You have at least 1 uppercase in this username.")

            else:
                print ("You have no uppercase in this username.")

        numlower = 0

        for d in username:

            if d.islower() == True:
                numlower +=1
            if numlower > 0:
                print ("You have at least 1 lowercase in this username.")

            else:
                print ("You have no lowercase in this username.")


        numdigit = 0

        for e in username:

            if e.isdigit() == True:
                numdigit += 1
            if numdigit > 0:
                print ("You have at least one digit in this username.")

            else:
                print("You have no digits in this username.")

        else:
            print("Please try again")
            continue

    except:
        print ("Sorry, not valid. Try again.")
    else:
        print ("Thank you for your input")
        break

when I run this definition using my main program:

import uservalidation


username = input("Username: ")


result, reason = uservalidation.valid_username(username)


if not(result):
    print (reason)

I get this (depending on how many letters i enter in):

Username: craig
Sorry, the username must be at least 8 characters long.
You have no uppercase in this username.
You have no uppercase in this username.
You have no uppercase in this username.
You have no uppercase in this username.
You have no uppercase in this username.
You have at least 1 lowercase in this username.
You have at least 1 lowercase in this username.
You have at least 1 lowercase in this username.
You have at least 1 lowercase in this username.
You have at least 1 lowercase in this username.
You have no digits in this username.
You have no digits in this username.
You have no digits in this username.
You have no digits in this username.
You have no digits in this username.
Please try again

How can I change my code so that it’ll only show statements such as “you have at least lowercase in this username” only once. thanks you so much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:25:53+00:00Added an answer on June 15, 2026 at 2:25 pm

    Your indentation is off:

    for c in username:
        if c.isupper() == True:
            numupper += 1
    
        if numupper > 0:
            print ("You have at least 1 uppercase in this username.")
        else:
            print ("You have no uppercase in this username.")
    

    So for each character, you are printing the error text. What you want to do instead is to move the check on the number outside of the loop:

    for c in username:
        if c.isupper() == True:
            numupper += 1
    
    if numupper > 0:
        print ("You have at least 1 uppercase in this username.")
    else:
        print ("You have no uppercase in this username.")
    

    So after you have counted the upper case characters (in the loop), you evaluate the results and print the error text once.

    The same applies to the lowercase- and digit-check.

    Btw. you can use the same variable for different for-loops. So you do not need to use c, d and e, you can just keep using c. Also, you should consider merging your loops. In all three of them, you loop over the characters of the username, so you can do everything at the same time:

    numupper, numlower, numdigit = 0, 0, 0
    
    for c in username:
        if c.isupper():
            numupper += 1
        if c.islower():
            numlower +=1
        if e.isdigit():
            numdigit += 1
    
    # and now check numupper, numlower and numdigit
    

    Also, as you can see, I removed the == True from the if conditions. It is generally a good practice to leave that out, as if already checks if the expression equals to true. So it’s basically redundant.

    And finally, you can do those checks a bit differently. For example you can check for lower- and uppercase characters by converting the string to the same and compare it with the original text. So username.lower() == username means that there are no uppercase characters in it; similarily username.upper() == username means that there are no lowercase characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my current code: import random while True: try: num = int(input(Enter the
This is my current code: while True: try: mylist = [0] * 7 for
I am having a bit of difficulty with this current code I have set
As a beginner in Ocaml, I have this current working code: ... let ch_in
if (webBrowser1.Url.AbsoluteUri == www.google.com) { label9.Text = webBrowser1.Url.AbsoluteUri; } This is my current code.
My current code is this $swift = email::connect(); $swift->setSubject('hello') ->setFrom(array('alex@example.com.au' => 'Alex')) ->setTo(array('alex@example.com.au' =>
This is my current search code. -(void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope { [filteredList removeAllObjects]; for(Location
This question is related to a previous question of mine That's my current code
I'm running code that sometimes yields this: UInt32 current; int left, right; ... //sometimes
The code i current have is this. function update (){ latest_id = $('#image:first').data('position'); /*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.