[Tutor] sequence of elements problem

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Nov 8 19:24:30 CET 2013


On 08/11/2013 12:54, donsuni wrote:
> Hi, I have a problem in python which is kind of tricky.
>
> if i give a sequence of numbers, i should get another sequence of numbers
> such that the the elements exceeds previous element in the list. For eg
>
> seq_num([3,2,5,7])=[3,5,7] since 5 is >3, and 7>5
> seq_num([1,2,3,4])=[1,2,3,4]  since 2 is >1, and 3>2 and so on
> seq_num([5,5,5])=[5]
> seq_num([9,8,7])=[9]
>
> and so on without using any inbuilt functions.
>
> I tried the following code but it is not incrementing:
>
> def seq_num(numlist):
>
>      n=len(numlist)
>
>      for i in range(0,n - 1):
>
>          if numlist[i]>numlist[i+1]:
>              i+=1
>              return numlist[i]
>

You've failed to meet the stated requirement as len and range are 
built-in functions so whether or not the increment occurs is irrelevant.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence



More information about the Tutor mailing list