
Patrick B. answered 03/16/21
Math and computer tutor/teacher
#############################################
# Problem #1
############################################
fruits = ["Apples","Bananas","Grapes","Watermelon","Strawberries","Cherries","Pineapple","Canteloupe","Oranges","Lemon"]
print(" Fruit length ")
for fruit in fruits:
fruitLen = len(fruit)
print(" " + str(fruit) + " " + str(fruitLen))
###############################################
# PROBLEM #2
###############################################
menuChoice = -1
while (int(menuChoice)<0) or (int(menuChoice)>2):
print("******************************")
print(" <1> Temperature Conversion ")
print(" <2> Mortgage Payment ")
print("*******************************")
menuChoice = input("Please input your selection or ZER0 to quit :>")
if (int(menuChoice)<0) or (int(menuChoice)>2):
print("Invalid selection...")
#######################################################
# PROBLEM #3
#######################################################
def CharStats( strBuff):
statsReturn=[]
numAlpha=0
numDigit=0
numMisc=0
strlength = len(strBuff)
for i in range(strlength):
curCharStr = strBuff[i]
if curCharStr.isalpha():
numAlpha=int(numAlpha)+1
elif curCharStr.isnumeric():
numDigit=int(numDigit)+1
elif len(curCharStr.strip())>0:
numMisc = int(numMisc)+1
statsReturn.append(numAlpha)
statsReturn.append(numDigit)
statsReturn.append(numMisc)
return(statsReturn)
#----------------------------------------------------------------
strBuff="The 2 quick, brown foxes jumped over the 3 lazy dogs."
charStats = CharStats(strBuff)
print(charStats)
strBuff="Today is March 17th, 2021 also formatted as 03/17/2021"
strBuff = strBuff+ " and in Europe it is 17/03/2021"
charStats = CharStats(strBuff)
print(charStats)
#####################################################
# PROBLEM #4
####################################################
def WordStats( strBuff):
wordStatsReturn=[]
totalStrLength=0
tokens = strBuff.split(" ")
wordCount = len(tokens)
for token in tokens:
print(token)
totalStrLength = int(totalStrLength)+len(token)
wordStatsReturn.append(wordCount)
wordStatsReturn.append(totalStrLength)
return(wordStatsReturn)
#---------------------------------
strBuff = "The sun was rising then it wasn’t, darkness was all"
strBuff = strBuff + " around until I saw the light"
strBuff = strBuff + " and all was well"
buffStats = WordStats(strBuff)
print(buffStats)