Question: How is the below python code work ? Please explain step by step , explain why input zyda output is6, inputafcbdoutput is4 Thanks in advance.

How is the below python code work ? Please explain step by step , explain why input "zyda "output is"6", input"afcbd"output is"4" Thanks in advance.

def find_out_of_order(inputString): out_of_order = 0 for i in range(0, len(inputString)): for j in range(i + 1, len(inputString)): if inputString[j] < inputString[i]: out_of_order += 1 return out_of_order

inputs = ["abcdef", "zyda", "afcbd"] for inp in inputs: res = find_out_of_order(inp) print(inp, res)

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!