write a piece of code that ask the user to set a password
- queries the user for his/her user name
- queries the user for his/her password twice, making sure the user
enters the same password twice
- Allow Only 3 attempts to get a correct password

the rules for the password are
- at least one number
- at least one lower cap letter
-
at least one upper cap letter
- allowed characters: numbers, letters, "_", "-" and "."

Member Avatar for Enalicho

Quoted from the rules -

Naturally giving away the answer is a subjective thing, so just make sure that the person you help can't just take your code and turn it in for a grade. We want the people we help to do enough work to learn something meaningful.

This question looks _a lot_ like homework. If it's not, why not have a go at it yourself first, then post what you get stuck on?

Here's some pseudocode to help you along -

INPUT username
SET count = 0
WHILE INCORRECT password AND count IS LESS THAN 3:
    INPUT first_password_attempt
    INCREMENT count BY 1
    IF first_password_attempt is VAILD PASSWORD:
        INPUT second_password_attempt
        IF first_password_attempt IS THE SAME AS second_password_attempt:
            SET password AS CORRECT
        ELSE:
            SET password AS INCORRECT
    ELSE:
        SET password as INCORRECT

As for checking if the password is valid, look into either regular expressions or using the string module.

i have been trying that but i was not able to get the correct result. It is not homework it is problem(self exercise) from book that i have reading for python. i have lot of doubts but no one clear.

Hi Members
Write a regular expression that matches any and only the strings that start A, and end with B, with anything inbetween.
if given string is AAAAABCBCBCBCBB

Hi all
In Python:
i am looking for syntax that is used for finding lowercase or uppercase in string and also syntax to find the number as well as special character in string.

Member Avatar for Enalicho

If it's not homework, then I'm sure you'll have no problems with posting the code you've done so far. I'm not going to give you the answer - you don't learn anything that way.

Read the regular expression documentation - http://docs.python.org/library/re.html

Hi
thanks for the reply. Here is code that i am working on for finding the string start with A and ends with B.

s='AAAAAABBBBABABAB'
for letter in s:
if letter=='A':
print'string start with A'
if s[:14]=='B':
print'string ends with B'
here is the problem i am not understanding if first condition fail it w'not go inside the loop but i want check both the condition before coming out of the loop.

And as far as password program the thing u have given i very help full but one more doubt i have in that how to find the uppercase or lowercase in string?

i wish i would get any help in that.

Member Avatar for Enalicho
def starts_with_a_ends_with_b(word):
    return word[0]=='A' and word[-1]=='B'
print starts_with_a_ends_with_b('AAAAAABBBBABABAB')

In python, we have the benefit of accessing lists and strings through negative numbers to indicate we're indexing starting from the end.
Your for loop isn't great, because there's no need to do it for every letter in the string! Don't use a loop unless you have to, a single loop will run N times, whereas my code will run once and only once, no matter what.

As for finding upper or lowercase characters, there are several ways of doing it. You can test the ord() value of the character to tell if it's uppercase or lowercase (try ord('A'),ord('Z'),ord('a') and ord('z') and see what you get), or use A-Z for uppercase and a-z for lowercase in regular expressions, or use ascii_uppercase
and ascii_lowercase from the string module and use the "in" statement to test.

Hi Enalicho
Sorry to bother u again can u give me your email id or something i want to talk to you about that program and discus.

Thanks my email id is [removed]

Hi Enalicho
That is correct u said but if we want to check some more patten in the string like if string is'AAAABBBOXXOBBB'and we need to check for 'OX or XO in the middle then what we will do.

i am looking for code that ask the user to set a password
- queries the user for his/her user name
- queries the user for his/her password twice, making sure the user
enters the same password twice
- Allow Only 3 attempts to get a correct password

the rules for the password are
- at least one number
- at least one lower cap letter
- at least one upper cap letter
- allowed characters: numbers, letters, "_", "-" and "."


plzzz any one know the code peply me i need this very urgent.
Any help will be very helpfull..

Member Avatar for Enalicho

My email is on my profile. What questions did you have about the program?

To check for something in the string, then we use "in", for example

'OX' in 'AAAABBBOXXOBBB'

which will return True if OX is in the string, False otherwise.
Editing the program to include this, we end up with -

def matches_pattern(word):
    return word[0]=='A' and word[-1]=='B' and ('OX' in word or 'XO' in word)
print matches_pattern('AAAABBBOXXOBBB')

At this stage, a regex would be better, for example -

def matches_A_OX_B(word):
    if re.match('A.*[OX|XO].*B',word) is None:
        return False
    return True

For more information on this, read the re documentation.

Hi Enalicho
The solution that u have given for finding pattern is showing any output if we give some test string to test as well. So any suggestion in that.

Thanks

Hi All the members
can anybody tell me the syntax for finding the exact match for the given string.
EX: Given string is 'AAAABCADCAXC' and we need to find any of them in given string and report that 'ABC','ADC',AXC'

Hi Any one
Plzz help me out

import re                                   # Using the Regular Experssions
s='ABCAAABCB'                            # intalise the string
x='ABC'                                           #intalise the sub string
match= re.search('x','s')                     # searching the sub string in string
if match:                                            # condition true 
print "Match:",x                                 # Print the Matching sub string
else:                                                  # condition False
print"No match"

Can any body tell me what is wrong in this program not giving any output

Member Avatar for Enalicho
match= re.search('x','s')

match is equal to the return from re.search, using the pattern 'x' and the string 's'.
What you want is

x

and

s

, not the strings 'x' and 's'.

It's hard to comment any further without the correct indentation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.