Q:

Write a Python function to convert a given string to all uppercase if it contains at least 2 uppercase characters in the first 4 characters.

0

Write a Python function to convert a given string to all uppercase if it contains at least 2 uppercase characters in the first 4 characters.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def to_uppercase(str1):
    num_upper = 0
    for letter in str1[:4]: 
        if letter.upper() == letter:
            num_upper += 1
    if num_upper >= 2:
        return str1.upper()
    return str1

print(to_uppercase('Python'))
print(to_uppercase('PyThon'))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now