Answer:
See explaination
Explanation:
def readFileFirstLast(filename):
# doc string
''' Function accept the filename and opens the fle
and reads all lines and strips new line character and
stores first and last in a string and return that string'''
#eception handle if file not found
try:
#opening the file
f = open(filename)
#reading the first line and striping the ne line
string = f.readline().strip()
#iterating until last line
for line in f:
pass
#concate the last line after strip the new line character to the string
string = string + " " + line.strip()
#return the string
return string
except:
#if file not found
return "File not found"
#taking the file name from user
filename = input("Enter a file name: ")
#printing the doc string in function
print("\ndoc_sting: \n"+ readFileFirstLast.__doc__+"\n")
#printing the returned string by calling the readFileFirstLast()
print("output string :")
print(readFileFirstLast(filename))
Answer:
The answer is (C)
Let’s run the algorithm on a small input to see the working process.
Let say we have an array {3, 4, 1, 5, 2, 7, 6}. MAX = 7
- Now for i=0, i < 7/2, here we exchange the value at ith index with value at (MAX-i-1)th index.
- So the array becomes {6, 4, 1, 5, 2, 7, 3}. //value at 0th index =3 and value at (7-0-1)th index is 6.
- Then for i=1, i < 7/2, the value at index 1 and (7-1-1)=5 are swapped.
- So the array becomes {6, 7, 1, 5, 2, 4, 3}.
- Then for i=2, i < 7/2, the value at index 2 and (7-2-1)=4 are swapped.
- So the array becomes {6, 7, 2, 5, 1, 4, 3}.
- Then for i=3, i not < 7/2, so stop here.
- Now the current array is {6, 7, 2, 5, 1, 4, 3} and the previous array was{3, 4, 1, 5, 2, 7, 6}.
Explanation:
So from the above execution, we got that the program reverses the numbers stored in the array.
Answer:
- def getLargest(number_list):
- new_list = []
-
- for x in number_list:
- if(isinstance(x, int)):
- new_list.append(x)
-
- largest = max(new_list)
-
- return largest
Explanation:
Firstly, create a function <em>getLargest()</em> that take one input parameter, <em>number_list</em>.
The function will filter out the float type number from the list by using <em>isinstance() </em>method (Line 5). This method will check if a current x value is an integer. If so, the x value will be added to <em>new_list</em>.
Next, use Python built-in <em>max</em> function to get the largest integer from the <em>new_list </em>and return it as output.
The "Begins With" criteria filter is what your looking for