Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CONVERT THE FUNCTION CALLED EXCEED FROM ITS CURRENT MATLAB LANGUAGE TO PYTHON LA

ID: 669801 • Letter: C

Question

CONVERT THE FUNCTION CALLED EXCEED FROM ITS CURRENT MATLAB LANGUAGE TO PYTHON LANGUAGE. STEP BY STEP DESCRITIONS ARE GIVEN FOR EACH PART OF THE CODE!

---------------------------------------------------------------------------------------------------------------------------------------------------

function nexceed = exceed(array, threshold)

%% *********************************************************************

%

% exceed [Number of array elements above the threshold]

%

% Syntax: nexceed = exceed(array, threshold)

%

% Inputs:

%    array - Array with elements.

%    threshold - Number specifying the threshold to exceed.

%

% Outputs:

%    nexceed - Number of elements that exceed the threshold.

%  

% Author: Hans Chen with comments added by Eugene Clothiaux

% Email: hans.chen@psu.edu

%

%-----------------------------------------------------------------------

%% ---------------------------------------------------------------------

% Easy way of solving the problem using Matlab features.

%-----------------------------------------------------------------------

nexceed = sum(array > threshold);

%% ---------------------------------------------------------------------

% Traditional way using a loop.

%-----------------------------------------------------------------------

% Set the counter variable to 0.

nexceed = 0;

% Loop through all temperatures in the array, testing each one to

% determine whether or not it is above the threshold.

for i = 1:length(array)

    % Test to determine if a temperature is above the threshold.

    if array(i) > threshold

        % If it is, count it!

        nexceed = nexceed + 1;

    end

end

%***********************************************************************

% DONE with the function exceed.

Explanation / Answer

ANSWER:

Threshold.py

def excedd(temp_array,x):
count=0;
for w in temp_array:
if w > x:
count = count + 1
print " Number of elements exceeded threhold is :"
print count
return


temp_array = list()
num = raw_input("How many elements you want:")
print ' Enter numbers in array: '
for i in range(int(num)):
n = raw_input(" Num :")
temp_array.append(int(n))
x = int(raw_input(" Please enter threshold value: "))
excedd(temp_array,x)

OUTPUT:

How many elements you want:4
Enter numbers in array:

Num :6
Num :7
Num :9
Num:10

Please enter threshold value: 8
Number of elements exceeded threhold is :
2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote