# Tutorial 3 - Problem 3 ##def any_lowercase1(s): ## """ This function only looks at the first letter in s ## returning True if it is lowercase, False otherwise. ## """ ## for c in s: ## if c.islower(): ## return True ## else: ## return False # First, here is the above function re-written based on GPS: # Note that this is extra, this was not asked in Problem 3 def first_letter_is_lowercase(aString): """ This function only looks at the first letter in its parameter aString and returns True if this letter is a lowercase letter, False otherwise. Pre-condition: parameter aString cannot be an empty string and it must be composed of characters that will not crash the program when the string method .islower() is called. """ returnedValue = False # Return True if the first letter of aString is a lowercase letter if aString[0].islower(): returnedValue = True return returnedValue # Answer to Problem 3: # The function below returns True if there are any lower case letters # in the string parameter (at least one). def any_lowercase(aString): """ This function returns True if there are any lower case letters in the string parameter, False otherwise. Pre-condition: parameter aString cannot be an empty string and it must be composed of characters that will not crash the program when the string method .islower() is called. """ returnedValue = False # Return True if the first letter of aString is a lowercase letter for letter in aString: if letter.islower(): returnedValue = True return returnedValue # Main part of program # What test data will we use to test this function? # Here are some: print('first_letter_is_lowercase("paul")): ', first_letter_is_lowercase("paul")) print('first_letter_is_lowercase("Paul")): ', first_letter_is_lowercase("Paul")) print('first_letter_is_lowercase("PAUl")): ', first_letter_is_lowercase("Paul")) print('first_letter_is_lowercase("PAUL")): ', first_letter_is_lowercase("PAUL")) print('first_letter_is_lowercase("pAUL")): ', first_letter_is_lowercase("pAUL")) # Can we create a few more test cases? print('any_lowercase("paul")): ', any_lowercase("paul")) print('any_lowercase("Paul")): ', any_lowercase("Paul")) print('any_lowercase("PAUl")): ', any_lowercase("Paul")) print('any_lowercase("PAUL")): ', any_lowercase("PAUL")) print('any_lowercase("pAUL")): ', any_lowercase("pAUL")) # Actual results from our test cases: ##first_letter_is_lowercase("paul")): True ##first_letter_is_lowercase("Paul")): False ##first_letter_is_lowercase("PAUl")): False ##first_letter_is_lowercase("PAUL")): False ##first_letter_is_lowercase("pAUL")): True ##any_lowercase("paul")): True ##any_lowercase("Paul")): True ##any_lowercase("PAUl")): True ##any_lowercase("PAUL")): False ##any_lowercase("pAUL")): True