473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Python Case Sensitive Help....

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:

Expand|Select|Wrap|Line Numbers
  1. # -*- coding: cp1252 -*-
  2. from easygui import *
  3.  
  4. accounttype=buttonbox("Would you like to create an account or login?", "Password Storage System Pro", choices=["Login","New Account"])
  5.  
  6. if accounttype=="Login":
  7.     multpasswordbox("Enter Your Account Information", "Login", ["User ID","Password"])
  8.     msgbox("Thank you for using Password Storage System Pro, \nPlease Try Again Later.")
  9. if accounttype=="New Account":
  10.     newaccount=multpasswordbox("Enter Your Account Information", "New Account", ["User ID","Password"])
  11.     confirm=passwordbox("Please Validate Your Password", "Password")
  12.     while newaccount[1]==confirm:
  13.         msgbox("Thank you for using Password Storage lolSystem Pro")
  14.         password=confirm[1]
  15.         i=0
  16.         cap=0
  17.         low=0
  18.         dig=0
  19.         while i<len(password):
  20.             if password[i] >= "A" and password[i] <= "Z":
  21.                 cap=cap+1
  22.             if password[i] >= "a" and password[i] <= "z":
  23.                 low=low+1
  24.             if password[i] >= "0" and password[i] <= "9":
  25.                 dig=dig+1
  26.             i=i-1
  27.             if cap>0 and low>0 and dig>0:
  28.                     print "Thank You for registering"
  29.  
  30. print cap
  31. print low
  32. print dig
  33.  
  34. if newaccount[1]!=confirm:
  35.     msgbox("Your Passwords did not match. Try again please.")
  36.     confirm=passwordbox("Please Validate Your Password", "Password")
  37. password=confirm[1]
  38. i=0
  39. cap=0
  40. low=0
  41. dig=0
  42. while i<len(password):
  43.     if password[i] >= "A" and password[i] <= "Z":
  44.         cap=cap+1
  45.     if password[i] >= "a" and password[i] <= "z":
  46.         low=low+1
  47.     if password[i] >= "0" and password[i] <= "9":
  48.         dig=dig+1
  49. i=i-1
  50.  
  51.  
  52. print cap
  53. print low
  54. print dig
Feb 20 '08 #1
1 2773
bvdet
2,851 Expert Mod 2GB
Following are a some different approaches that may help you.
Expand|Select|Wrap|Line Numbers
  1. import re
  2.  
  3. pattU = re.compile(r'[A-Z]')
  4. pattL = re.compile(r'[a-z]')
  5. pattD = re.compile(r'[0-9]')
  6.  
  7. word = 'AdjiV560dfRGh'
  8.  
  9. print pattU.findall(word)
  10. print pattL.findall(word)
  11. print pattD.findall(word)
  12.  
  13. print len(pattU.findall(word))
  14.  
  15. >>> ['A', 'V', 'R', 'G']
  16. ['d', 'j', 'i', 'd', 'f', 'h']
  17. ['5', '6', '0']
  18. 4
Expand|Select|Wrap|Line Numbers
  1. import string
  2.  
  3. word = 'AdjiV560dfRGh'
  4. print len([letter for letter in word if letter in string.ascii_lowercase])
  5. print len([letter for letter in word if letter in string.ascii_uppercase])
  6. print len([letter for letter in word if letter in string.digits])
  7.  
  8. >>> 6
  9. 4
  10. 3
  11. >>>
Instead of duplicating inline code, you can use a function
Expand|Select|Wrap|Line Numbers
  1. # Function returns True if word contains upper case, lower case and digits
  2. # Otherwise returns false
  3. def validate_word(word):
  4.     tt = (len([letter for letter in word if letter in string.ascii_lowercase]), \
  5.           len([letter for letter in word if letter in string.ascii_uppercase]), \
  6.           len([letter for letter in word if letter in string.digits]))
  7.     if 0 in tt: return False
  8.     return True
  9.  
  10. print validate_word('guenhfnm58976')
  11. print validate_word('guenhfASZnm58976')
  12.  
  13. >>> False
  14. True
  15. >>> if validate_word('guenhfASZnm58976'):
  16. ...     print 'Success'
  17. ... else:
  18. ...     print 'Failure'
  19. ...     
  20. Success
  21. >>> 
Feb 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
44
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...
0
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...
9
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...
2
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: ...
0
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...
32
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:
38
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.