Posted on

20/11/13 – Test!

Today we had our first computing test ever! After the theory, there were 2 short programming task. The first was to create a function which took in a number as input, and told you whether it was odd or even. I did this by using the mod (remainder) function to see how what the remainder of dividing the input number by 2 was. If the reminder was 1, then it was an odd number as it was not divisible by 2, else it was an even number.

Screen Shot 2013-11-23 at 16.23.51

 

The second was slightly harder, and asked you to use a while loop to get 3 scores from a test and print the largest value. My initial method was to use ask for 1 input each time you went through the list, which then get appended to the list called marks. Each time you went through the loop you would add 1 to the count variable , so that when count would reach 3, the function will stop, as you have entered the 3 required values. Finally, I print the max number of the list, which should be the top mark.

Screen Shot 2013-11-23 at 16.25.50

Some would argue that using the max function involves no actual logic and defeats the point of the task. So I decided to have another go a the task, instead this time without using a max function, and still abiding by the task specification.

Screen Shot 2013-11-23 at 16.35.24

 

This time my function goes through the list and checks against the maxnum, to see if the input value is greater. If it is greater, the if changes the variable maxnum to the inputed number. Both function resulting in the same output.

Screen Shot 2013-11-23 at 16.37.10

Leave a comment