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 7438733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:36:01+00:00 2026-05-29T10:36:01+00:00

The task is to get a user to input a password then, using recursion,

  • 0

The task is to get a user to input a password then, using recursion, make sure it has no vowels in it. If it does then let the user re-enter the password. This is what i have so far:

def passwordCheck(pwd):
    """checks if pwd has any vowels in it."""#doc string
    vowels = 'aeiou'#specifies the characters that aren't allowed
    if pwd == '':
        return 0
    elif pwd == None:
        return None#Shouldn't be necessary but just in case
    elif pwd[0] not in vowels:#checks that the 1st(0th) character is not a vowel
        return passwordCheck(pwd[1:])#gets rid of the 1st(0th) character and starts again
    elif pwd[0] in vowels:#checks if the 1st(0th) character is a vowel
        return 1#if it is, stops the function calls and returns a value

password = str(input('Please enter a password with no vowels in it: '))#asks user to input their new password
x = passwordCheck(password)#checks the password is valid, i.e. no vowels

while x == 1:#when the password entered contains a vowel
    print('\nSorry, that is not a valid password.\nYour password cannot contain any vowels.')#tells the user why their password is invalid
    password = str(input('\nPlease enter a different password: '))#gives the user a chance to re-enter their password
    x = passwordCheck(password)#checks to make sure the new password is valid

print('\nCongratulations, you have entered a valid password!')#tells the user if their desired password is valid
print('\nYou are now able to log on to the system with these credentials.')#could've been included on the previous line but looks neater here

I know this is probably not the most pythonic way of doing it but it works for me in most cases. I’d love to hear a better way but ideally someone can help in the same style. I don’t want to just copy someones code without understanding it.

The question i have is dealing with the case where the user enters no password at all. The first if statement:

if pwd == '':
    return 0

I thought it just dealt with the case when the string had been fully recursed through, i.e. no vowels, but after a minutes inspection it’s obvious this applies to no password as well.
I had also tried using:

if pwd == None:
    return something

Now i’m thinking the problem could be because i said:

password = str(input('######'))

but i’ve fiddled with that as well and still can’t can’t seem to make that work either! I’ve tried google and searching stackoverflow but no luck so if anyone has any ideas/solution they think might be helpful I’d be very grateful to hear them. Thank you very much.

My main question is:

How can i differentiate between a string that’s empty because it’s been recursed through and the user inputting nothing?

Solved.

ended up using

def passwordValid(pwd):
if len(pwd)>0 and passwordCheck(pwd)==0:
    return pwd
else: return 'Fail'

password = str(input('Please enter a password with no vowels in it: '))#asks user to input their new password
y = passwordValid(password)#checks the password is valid, i.e. no vowels

while y == 'Fail':#when the password entered contains a vowel
    print('\nSorry, that is not a valid password.\nYour password cannot contain any vowels or be empty.')#tells the user why their password is invalid
    password = str(input('\nPlease enter a different password: '))#gives the user a chance to re-enter their password
    y = passwordValid(password)#checks to make sure the new password is valid


print('\nCongratulations, you have entered a valid password!')#tells the user if their desired password is valid
print('\nYou are now able to log on to the system with these credentials.')#could've been included on the previous line but looks neater here

Thank you Wayne Werner for fixing the title and the main question.

  • 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-05-29T10:36:02+00:00Added an answer on May 29, 2026 at 10:36 am

    This problem can be broken down into (at least) three distinct subproblems:

    • check whether a string contains vowels
    • check whether a string is a valid password (length > X and has vowels)
    • get a password from the user

    Your code should reflect this structure. You could therefore use the following function layout:

    def has_vowels(string):
      if not string:  # check for empty string
        return False  # empty strings never have vowels
      # TODO we have a non-empty string at this point and can use recursion
    
    def is_valid_password(string):
      return len(string) > 0 and not has_vowels(string)
    
    def request_password():
      while True:   # use an endless loop here, we don't won't to repeat
                    # the "input" statement. We could also change this to
                    # something like `for i in range(3)` to allow only a limited
                    # number of tries.
        passwd = input('Please enter a password with no vowels in it: ')
        # TODO check if input is valid, if yes, return, if no, print an error
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ant's get task to save a file to disk. I am
I'm trying to get user input and allowing them to only input a whole
I'm quite new to javascript but have undertaken a task to get better aquainted
Target failed to run: Remote exception encountered: Faild to get task for pid 3103
I get the following error when I run my task via DelayedJob: closed stream
How can I get the javac task to use an existing fileset? In my
How can I get at the Labels data from within my Task model? class
I have a custom MSBuild task that peeks inside an assembly to get some
I have managed to get a cron job to run a rake task by
This somehow simple task is not so simple. I can get the number of

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.