Question: python 3.7.8 #3)The following programs are not working correctly. Find and resolve the error(s) so they work as intended. Above each code snippet is a

python 3.7.8

#3)The following programs are not working correctly. Find and resolve the error(s) so they work as intended. Above each code snippet is a description of how the program should function.

#3.1) The following function takes a filename as a parameter and returns the number of words in the file.

def wordcount(fname): countofwords = 0 infile = open(fname,'r') s = infile.readline() infile.close() s = s.split() return len(s)

#3.2) The following function takes a string as a parameter and returns a list containing all of the digits in the string. The list contains integers rather than strings. If there are no digits in the string, an empty list is returned. If a digit appears multiple times, it is included in the list multiple times.

def findDigits(s): newLst=[] for char in s: for i in range (0,10): if str(i) = char: newLst.append(i) return newLst

#Example output: #>>>findDigits(3 2 1 blastoff!) #[3,2,1] #>>> findDigits(Testing 1, testing 12, testing 123.) #[1,1,2,1,2,3] #>>> findDigits(There are no digits here) #[]

#3.3) The following function HALF takes a list of numbers and returns True of each element is exactly half the previous, and False otherwise. #Test with the following: #a = [7,5,3,1] returns False #b = [4,3,2,1] returns False #c = [20,10,5] returns True

HALF(nums): for i in range(0,len(nums)-1): if nums[i+1] == (nums[i]*2): pass else: return False return True

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!