Generation

generate functionSun, 18 Dec 2022

Write a function that will check if two given characters are the same case. If either of the characters is not a letter, return -1 If both characters are the same case, return 1 If both characters are letters, but not the same case, return 0 Examples 'a' and 'g' returns 1 'A' and 'C' returns 1 'b' and 'G' returns 0 'B' and 'g' returns 0 '0' and '?' returns -1

def same_case(a, b): if a.isalpha() and b.isalpha(): if a.islower() and b.islower(): return 1 elif a.isupper() and b.isupper(): return 1 else: return 0 else: return -1 same_case('a', 'g') # 1 same_case('A', 'C') # 1 same_case('b', 'G') # 0 same_case('B', 'g') # 0 same_case('0', '?') # -1

Questions about programming?Chat with your personal AI assistant