Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for All Upper II by delahere
# Taken from mission All Upper I
def is_all_upper(text: str) -> bool:
# your code here
# To determine if a string has all caps or is empty or doesn't
# have any upper case letters, create a string of the lower
# case alphabet.Step through each character and if a lower case
# letter is return False.
# If all of the characters have been processed and no lower
# case letters have been found, return True.
#
# Empty strings or strings with no letters at all should return
# False.
#
lower_case = "abcdefghijklmnopqrstuvwxyz"
char_count = 0
for char in text:
#
# If at least one of the characters in the text is in lower case,
# return False
#
if char in lower_case:
return False
#
# Force the character to lower case to see if it is, in fact,
# a character. We need at least one to return True
#
if char.lower() in lower_case:
char_count += 1
if char_count == 0:
return False
return True
print("Example:")
print(is_all_upper("ALL UPPER"))
# These "asserts" are used for self-checking
assert is_all_upper("ALL UPPER") == True
assert is_all_upper("all lower") == False
assert is_all_upper("mixed UPPER and lower") == False
assert is_all_upper("") == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
April 19, 2023