
Ethan H.
asked 03/17/21Strings Lab 3 questions
Separate the 4 programs with blank lines to make it more readable and label each problem such 1,2,3,4. I dont need extensive comments only the header section.
Each problem is worth 10 points.
Strings_Lab:_3
- Write a list that contains 10 fruits(no duplicate fruits). Loop through the list and print out the length of each fruit in the list. The output should be formatted as the example below with the titles and the values.
Fruit Length
Apples 6
Bananas 7
- Create a menu that the user can pick from the following options, Temperature Conversion, Mortgage Payment and Exit. The menu should be designed so that if a wrong option is picked a statement will be presented to the user and the menu will be displayed again for the user to enter a valid option.
3. The following string contains numbers, letters and special characters. Print out the number of letters, numbers and special characters(does not include spaces) in the string.
mystring = “Today is March 17th, 2021 also formatted as 03/17/2021 and in Europe it is 17/03/2021”
example given of output format:
Type numbers
letters 10
numbers 11
Special characters 4
- The following strings contains lots of words. Determine how many words are in the string along with the total length of all words in the string.
mystring = “The sun was rising then it wasn’t, darkness was all around until I saw the light and all was well”
1 Expert Answer

Patrick B. answered 03/17/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)
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
exactly the same as ANDREW K. yesterday03/17/21