Posts

Showing posts with the label a level cs p4 past paper

Underrated step for logic building in programming.

Image
Logic building is a crucial and complex skill in programming. In essence, it is ability to come-up with solution of coding problem and write precise instructions ( or code) that a computer can execute autonomously. This skill requires aligning your thought process with computer and its capabilities. And running through code some-what abstractly to know and predict the behavior of code before it is executed. To be able to do this, one essential step that many beginner programmers overlook is performing dry runs. Understanding Dry Runs The concept of a dry run in programming is straightforward: can you mentally execute your code and predict its output without actually running it on a computer? While this seems simple, it is a challenging task. Typically, we are taught to write code, run it, and observe the output. This cycle is essential because code needs to run to be validated. However, if you rely solely on running your code to understand its behavior, you may struggle with building...

9618_s22_qp_42

Image
  def BinarySearch (SearchArray, Lower, Upper, SearchValue): if Upper >= 0 : Mid = int ((Lower + (Upper - 1 )) / 2 ) if SearchArray[Mid] == SearchValue: return Mid elif SearchArray[Mid] > SearchValue: return BinarySearch(SearchArray, Lower, Mid - 1 , SearchValue) else : return BinarySearch(SearchArray, Mid + 1 , Upper, SearchValue) return - 1

9618/41/M/J/21

Image
  arrayData = [ 10 , 5 , 6 , 7 , 1 , 12 , 13 , 15 , 21 , 8 ] def linearSearch (searchValue): for x in range ( 0 , 10 ): if arrayData[x] == searchValue:      return True return False arrayData = [ 10 , 5 , 6 , 7 , 1 , 12 , 13 , 15 , 21 , 8 ] searchValue = int ( input ( "Enter the number to search for" )) returnValue = linearSearch(searchValue) if returnValue == True : print ( "It was found" ) else : print ( "It was not found" )

Popular posts from this blog