473,698 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python Case Sensitive Help....

1 New Member
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 2784
bvdet
2,851 Recognized Expert Moderator Specialist
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
2574
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...
44
2519
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...
0
1167
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
9
3440
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...
2
5753
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
0
293
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 ______________________
32
2847
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
13191
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
3
2167
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...
0
9170
Oralloy
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...
0
9031
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 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...
1
8904
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,...
0
8876
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 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...
0
5867
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();...
0
4372
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...
1
3052
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
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
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...

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.