write a program which takes a list as an input and returns True if the list is sorted and False otherwise
# sorted.py which takes a list as an input and returns True if the list is sorted and False otherwise
one=[1,3,9,8,2]
two=[1,2,3,4]
# size=len(one)
size=len(two)
def sorted_or_not(list_val):
if list_val == [] or list_val[size-1:] > list_val[size-2:] :
return True
else :
return False
def main():
if sorted_or_not(two):
print('It has returned True')
else:
print('It has returned False')
if __name__=="__main__":
main() # call main function
# print("{0:#b}".format(15))
# print(hex(78))
# '0b10110' Print this post
one=[1,3,9,8,2]
two=[1,2,3,4]
# size=len(one)
size=len(two)
def sorted_or_not(list_val):
if list_val == [] or list_val[size-1:] > list_val[size-2:] :
return True
else :
return False
def main():
if sorted_or_not(two):
print('It has returned True')
else:
print('It has returned False')
if __name__=="__main__":
main() # call main function
# print("{0:#b}".format(15))
# print(hex(78))
# '0b10110' Print this post
Comments
Post a Comment