मुझे एक फ़ंक्शन और मूल कोड का उपयोग करने का एक अच्छा तरीका मिला। यह एक ऐसा कोड है जो एक स्ट्रिंग को स्वीकार करता है और कैपिटल लेटर्स की संख्या, लोअरकेस लेटर्स और 'अन्य' को भी गिनता है। अन्य को अंतरिक्ष, विराम चिह्न या जापानी और चीनी वर्णों के रूप में वर्गीकृत किया गया है।
def check(count):
lowercase = 0
uppercase = 0
other = 0
low = 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
upper = 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
for n in count:
if n in low:
lowercase += 1
elif n in upper:
uppercase += 1
else:
other += 1
print("There are " + str(lowercase) + " lowercase letters.")
print("There are " + str(uppercase) + " uppercase letters.")
print("There are " + str(other) + " other elements to this sentence.")
character.isalnum() or character == "_"।