Python-courses-python-exercises

Exercise 92

Write a python program as a function which takes a string s as parameter and returns True if the string s contains at least one uppercase character and False otherwise.

Solution

def containsUpper(s):

# define and initialize a variable which counts the number of capitals
counter = 0

# browse the characters in the string s
for x in s:
# increment the counter each time the character encountered is in uppercase
if x.isupper ():
counter = counter + 1
if counter> 0:
return True
else:
return False
# Example
print (containsUpper ("djangoFramework")) # prints True
print (containsUpper ("djangoframework")) # prints false

Younes Derfoufi
my-courses.net

Leave a Reply