Hi All,
I'm using Windows Vista with Python 2.5. I need the code to check for case sensitive letters and digits, but something isn't right with it.
The code is below: - # -*- coding: cp1252 -*-
-
from easygui import *
-
-
accounttype=buttonbox("Would you like to create an account or login?", "Password Storage System Pro", choices=["Login","New Account"])
-
-
if accounttype=="Login":
-
multpasswordbox("Enter Your Account Information", "Login", ["User ID","Password"])
-
msgbox("Thank you for using Password Storage System Pro, \nPlease Try Again Later.")
-
if accounttype=="New Account":
-
newaccount=multpasswordbox("Enter Your Account Information", "New Account", ["User ID","Password"])
-
confirm=passwordbox("Please Validate Your Password", "Password")
-
while newaccount[1]==confirm:
-
msgbox("Thank you for using Password Storage lolSystem Pro")
-
password=confirm[1]
-
i=0
-
cap=0
-
low=0
-
dig=0
-
while i<len(password):
-
if password[i] >= "A" and password[i] <= "Z":
-
cap=cap+1
-
if password[i] >= "a" and password[i] <= "z":
-
low=low+1
-
if password[i] >= "0" and password[i] <= "9":
-
dig=dig+1
-
i=i-1
-
if cap>0 and low>0 and dig>0:
-
print "Thank You for registering"
-
-
print cap
-
print low
-
print dig
-
-
if newaccount[1]!=confirm:
-
msgbox("Your Passwords did not match. Try again please.")
-
confirm=passwordbox("Please Validate Your Password", "Password")
-
password=confirm[1]
-
i=0
-
cap=0
-
low=0
-
dig=0
-
while i<len(password):
-
if password[i] >= "A" and password[i] <= "Z":
-
cap=cap+1
-
if password[i] >= "a" and password[i] <= "z":
-
low=low+1
-
if password[i] >= "0" and password[i] <= "9":
-
dig=dig+1
-
i=i-1
-
-
-
print cap
-
print low
-
print dig
1 2784 bvdet 2,851
Recognized Expert Moderator Specialist
Following are a some different approaches that may help you. - import re
-
-
pattU = re.compile(r'[A-Z]')
-
pattL = re.compile(r'[a-z]')
-
pattD = re.compile(r'[0-9]')
-
-
word = 'AdjiV560dfRGh'
-
-
print pattU.findall(word)
-
print pattL.findall(word)
-
print pattD.findall(word)
-
-
print len(pattU.findall(word))
-
-
>>> ['A', 'V', 'R', 'G']
-
['d', 'j', 'i', 'd', 'f', 'h']
-
['5', '6', '0']
-
4
- import string
-
-
word = 'AdjiV560dfRGh'
-
print len([letter for letter in word if letter in string.ascii_lowercase])
-
print len([letter for letter in word if letter in string.ascii_uppercase])
-
print len([letter for letter in word if letter in string.digits])
-
-
>>> 6
-
4
-
3
-
>>>
Instead of duplicating inline code, you can use a function - # Function returns True if word contains upper case, lower case and digits
-
# Otherwise returns false
-
def validate_word(word):
-
tt = (len([letter for letter in word if letter in string.ascii_lowercase]), \
-
len([letter for letter in word if letter in string.ascii_uppercase]), \
-
len([letter for letter in word if letter in string.digits]))
-
if 0 in tt: return False
-
return True
-
-
print validate_word('guenhfnm58976')
-
print validate_word('guenhfASZnm58976')
-
-
>>> False
-
True
-
>>> if validate_word('guenhfASZnm58976'):
-
... print 'Success'
-
... else:
-
... print 'Failure'
-
...
-
Success
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: O'Neal Computer Programmer |
last post by:
*** First of all, if there is a previous post on Temple of Elemental
Evil, please provide a link to that/them so in order to create a
larger resource on this game. Thanks! (Merci) ;-) ***
Temple of Elemental Evil is a game for all us that don't know. It was
brought up previously on this board some months ago and recently I had
asked a question on whether this game would contain python scripting.
Well, first of all, Temple of Elemental...
|
by: Iwan van der Kleyn |
last post by:
Please ignore if you are allergic to ramblings :-)
Despite a puritan streak I've always tried to refrain from language wars
or syntax bickering; call it enforced pragmatism. That's the main reason
why I've liked Python: it's elegant and simple and still dynamic and
flexible. You could do worse for a clean and pragmatic language.
I do know my Smaltalk from my Common Lisp and my Ruby from my C#, so I
think I'm quite capable of escaping...
|
by: Simon Brunning |
last post by:
QOTW: "Not tested but confident should be an oxymoron for a
programmer." - Peter Otten
(Asked "Is this unsurprising if I look at it right?") - "Yes; in
general this is true across many domains for a very large number of
referents of "it" :-)" - John Machin
"Strong typing means there a lot of variables whose names are
in ALL CAPS." - Paul Rubin
|
by: Paul Smith |
last post by:
This doesn't seem like it should be *that* difficult, but after
quite some time trying to figure it out, I'm still banging my
head against the wall.
My objective is to examine the exact case-sensitive domain used
by the client to request a page, such as http://www.mysite.com vs.
http://www.MySite.com. As I spin through all the ServerVariables
and various & sundry HTTP headers (e.g. ALL_HTTP, ALL_RAW,
etc.), all I seem to pick up is the...
|
by: J. Muenchbourg |
last post by:
I'm doing a few tests with simple .net scripts, and I noticed that I
display the following error message at ErrMessage.Text if I don't enter
"BLUE" in capital letters into my input textbox:
<%@ Page Language="VB" %>
<script runat="server">
Sub Check_Value(Src As Object, Args As EventArgs)
If Color.Text <> "BLUE" Then
| |
by: Kurt B. Kaiser |
last post by:
Patch / Bug Summary
___________________
Patches : 396 open ( -5) / 3354 closed (+12) / 3750 total ( +7)
Bugs : 864 open (-32) / 6087 closed (+52) / 6951 total (+20)
RFE : 226 open ( +2) / 234 closed ( +1) / 460 total ( +3)
New / Reopened Patches
______________________
|
by: siggi |
last post by:
@Ben Sizer
Hi Ben,
in January I received your message re Pygame and Python 2.5:
As a Python (and programming ) newbie allow me a - certainly naive -
question:
|
by: Bart |
last post by:
Why is C case sensitive?
I know it's a bit late to change it now but there would seem to be far
more advantages in ignoring letter case in source code.
In real life such a situation would be ridiculous (eg. the 16 ways of
writing my name) and, in some cases, frightening.
Is it to avoid having to think up new identifiers? And how would you
distinguish case when reading out bits of code over the phone for
|
by: bsagert |
last post by:
I downloaded BeautifulSoup.py from http://www.crummy.com/software/BeautifulSoup/
and being a n00bie, I just placed it in my Windows c:\python25\lib\
file. When I type "import beautifulsoup" from the interactive prompt
it works like a charm. This seemed too easy in retrospect.
Then I downloaded the PIL (Python Imaging Library) module from
http://www.pythonware.com/products/pil/. Instead of a simple file that
BeautifulSoup sent me, PIL is...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |