This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def alpha_length(string): | |
| character = "" | |
| count_alpha = 0 | |
| # Complete the for loop sequence to iterate over "string". | |
| for i in string: | |
| # Complete the if-statement using a string method. | |
| if i.isalpha() : | |
| count_alpha += 1 | |
| return count_alpha | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def confirm_length(word): | |
| # Complete the condition statement using a string operation. | |
| if len(word)>=1: | |
| # Complete the return statement using a string operation. | |
| return len(word) | |
| else: | |
| return 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import datetime | |
| from datetime import date | |
| def add_year(date_obj): | |
| try: | |
| new_date_obj = date_obj.replace(year = date_obj.year + 1) | |
| except ValueError: | |
| # This gets executed when the above method fails, | |
| # which means that we're making a Leap Year calculation | |
| new_date_obj = date_obj.replace(year = date_obj.year + 4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def compare_strings(string1, string2): | |
| #Convert both strings to lowercase | |
| #and remove leading and trailing blanks | |
| string1 = string1.lower().strip() | |
| string2 = string2.lower().strip() | |
| #Ignore punctuation | |
| punctuation = r"[^\w\s]" # re.error: bad character range :-' at position 6 |