Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to check a string for specific characters?

I'm supposed to write a function that "Given a string s, return True if any character in that string is lowercase (between 'a' and 'z'), and False otherwise."

My code doesn't account for cases like ASDdFHU and ABCDeF

Attachment image

3 Answers

Relevance
  • Mike T
    Lv 5
    5 years ago

    import string

    def any_lowercase(s):

    for i in range(0,len(s)): #check each character using a for loop

    if(ord(s[i]) >= 97 and ord(s[i]) <= 122): #if the character at s[i] is between 'a' and 'z' in ascii, it must be a lowercase letter so return true

    return True

    return False

  • wg0z
    Lv 7
    5 years ago

    Standard C function islower() is your friend.

  • Chris
    Lv 7
    5 years ago

    Here's one way: http://ideone.com/ZPKLf5

    any() is a function, you can't use it like you tried.

Still have questions? Get your answers by asking now.