How to check if a string contains at least 2 uppercase characters in the first 4 characters with Python

1 Answer

0 votes
def check_at_least_2_uppercase_in_first_4(str):
    count_uppercase = 0
    for ch in str[:4]: 
        if ch.upper() == ch:
            count_uppercase += 1
    if count_uppercase >= 2:
        return True
    return False

print(check_at_least_2_uppercase_in_first_4('Python'))
print(check_at_least_2_uppercase_in_first_4('PytHon'))
print(check_at_least_2_uppercase_in_first_4('JaVA Programming'))



  
  
'''
run:
  
False
True
True
 
'''

 



answered Sep 1, 2021 by avibootz
...