Advertisement
homeworkhelp111

Code

Nov 16th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. def CheckIncrease(lst):
  2.     '''
  3.    This function returns the number of times an integer is followed immediately
  4.    by a bigger integer in lst.
  5.    For example, if lst = [1, 2, 1, 3, 4] then this function returns 3 since
  6.    1 followed by 2 is the first time an integer is immediately followed by a bigger integer
  7.    1 followed by 3 is the second time this hapens
  8.    and 3 followed by 4 is the last and final time an integer is followed by a bigger integer
  9.    Hence this function returns 3.
  10.    
  11.    More test cases listed below in main function along with
  12.    their expected output (inside comments)
  13.    '''
  14.     count = 0
  15.     for i in range(0,len(lst)-1):
  16.         if(lst[i+1] > lst[i]):
  17.             count +=1
  18.     return count
  19.    
  20.  
  21. def main():
  22.     print(CheckIncrease([1, 2, 3, 4, 5])) ## 4
  23.     print(CheckIncrease([1, 2, 2, 2, 2])) ## 1
  24.     print(CheckIncrease([2, 2, 2, 2, 2, 2])) ## 0
  25.     print(CheckIncrease([1, 2, 2, 2, 2, 3, 3, 3, 3])) ## 2
  26.     print(CheckIncrease([1, 2, 2, 2, 1, 3, 3, 3, 1])) ## 2
  27.     print(CheckIncrease([100, 50, 25, 12, 6, 3, 1])) ## 0
  28.     print(CheckIncrease([1, 2, 1, 3, 4])) ## 3
  29.     print(CheckIncrease([])) ## 0
  30.  
  31. main()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement