Menu

[Solved]-Python Make Function Checks List Ascending Order Functions Made Tried 1 Def Isincreasing D Q37280024

PYTHON

I have to make a function that checks if the list is in anascending order.

These are the functions I made and tried:

1.

def isIncreasing(data):
new = data.sort()
if data == new:
return True
return False

2.

def isIncreasing(data):

currentElement = data[0]
for i in range(1, len(data)):
if (currentElement > data[i]):
return False
currentElement = data[i]
return True

3.

def isIncreasing(data):

for i in range(len(data)-1):
if data[i] > data[i+1]:
return False
return True

I can run them, but they give out wrong answers.

For example, if I try these two lists: [1,2,3,4,5,6,7,8,9,10]and [12, 20, 10, 14, 54, 16, 75, 38, 79, 103], they both get Trueor they both get False. Obviously, the second list is not inascending order.

I don’t know what I did wrong, and I want to know the answer forthis question in python.

Expert Answer


Answer to PYTHON I have to make a function that checks if the list is in an ascending order. These are the functions I made and tr… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *