Skip to content

Instantly share code, notes, and snippets.

View poulamicode77's full-sized avatar
👩‍💻
Developer

Poulami Bhattacharyya poulamicode77

👩‍💻
Developer
View GitHub Profile
@poulamicode77
poulamicode77 / count_alphabet.py
Created December 10, 2025 07:57
4.Complete the for loop and string method needed in this function so that a function call like "alpha_length("This has 1 number in it")" will return the output "17". This function should: accept a string through the parameters of the function; iterate over the characters in the string; determine if each character is a letter (counting only alpha…
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
@poulamicode77
poulamicode77 / confirm_length.py
Last active December 10, 2025 07:53
3. Question 1 Fill in the blanks to complete the “confirm_length” function. This function should return how many characters a string contains as long as it has one or more characters, otherwise it will return 0. Complete the string operations needed in this function so that input like "Monday" will produce the output "6".
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
@poulamicode77
poulamicode77 / dateTime.py
Last active November 10, 2025 07:58
2.The datetime module supplies classes for manipulating dates and times, and contains many types, objects, and methods. You've seen some of them used in the dow function, which returns the day of the week for a specific date. We'll use them again in the next_date function, which takes the date_string parameter in the format of "year-month-day", …
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)
@poulamicode77
poulamicode77 / compareString.py
Last active November 10, 2025 07:57
1.The compare_strings function is supposed to compare just the alphanumeric content of two strings, ignoring upper vs lower case and punctuation. But something is not working. Fill in the code to try to find the problems, then fix the problems. Your goal is to search for the character “-” but - is typically reserved for ranges. Find a work-aroun…
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