This programming task will be a bit different. It will be more like what you would receive if you were a maintenance engineer working in a corporate information systems or technology department. In other words, you will have some prebuilt source code provided for you that you must alter so it will meet the given programming specification..
Note: Because the function Random() is used when filling the array, the number of times that 1320 occurs in the array of 10000 values will be different each time. Also, desk-checking an array of 10,000 numbers is an impractical way of validating the correctness of your program. As a result, you might consider adjusting the SIZE of the array and the RANGE of values randomly generated when testing. This is so one might use the "Watch Variables" feature and validate the programs output. A SIZE of 25 and a RANGE of 5 should work reasonably well. The values for the SIZE and RANGE should be reset before the program is turnt in.
import random
import array
def programHeader(number):
print ('Assignment {0} programmed by xyz.'.format(number))
def fillTheArray(itemp, size):
for i in range(size):
arr.append(random.randint(0, itemp))
def linearSearchOne(val):
if val in arr:
return True
def linearSearchTwo(val):
counter = 0
if val in arr:
counter = +1
return counter
def programOutput(boolval, iHowManyTimes):
print(boolval,iHowManyTimes)
if __name__ == '__main__':
arr = array.array('i',)
programHeader(1)
fillTheArray(10000, 2200)
a = linearSearchOne(1320)
b = linearSearchTwo(1320)
programOutput(a,b)
Get Answers For Free
Most questions answered within 1 hours.