29/11/13 – Computer System Presentation

This lesson I prepared a presentation about the first unit in the GCSE Computing Course of Computer System and how they operate. I also learned more about how an operating system function in relation to the hardware of a computer.

Screen Shot 2013-11-30 at 18.22.59

http://prezi.com/xkkvsd4lpwwh/?utm_campaign=share&utm_medium=copy

 

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

13/11/13 – Factorials

Today in class we were to make a program which solves the factorials of a value. A factorials is shown as a ‘!’ on your calculator and is the mathematical function which multiplies all the number which come before the number that is the coefficient of the factorial sign inclusive.

‘4!’ ———-> 4*3*2*1 = 24

However what made this task interesting was how we had to figure out the recommended logic using a given flowchart. As shown below.

flow_chartSo my solution involved going through a while loop and and multiplying the answer (originally set to 1) by the number entered. You change the value of the answer variable each time by setting it to the answer of the number multiplied by the answer. Also, every time you go through the loop you subtract 1 from the entered number. So when the number entered is equal to 1, the factorial, which is saved under the variable answer is printed.

Screen Shot 2013-11-23 at 15.41.16

I later realised I could have simplified this function in some ways. By putting my input into a for loop I have basically limited the range to which the function can multiply by the answer. Also I have also saved time, as I haven’t had to define another variable to house my input function. Thereby shortening my code by 4 lines. Yet I still have an idea with which I could shorten my code to 2 lines.Screen Shot 2013-11-23 at 15.54.25

25/10/13 – Python Challenges (Most Efficient Solutions in the Class!)

This was the last lesson before of the half term, and we were given a set of challenges to do in our given groups. The only way we could progress on to the next challenge was by completing the first. The winners would be the ones with the most challenges completed by the end of the lesson.

My group consisted of Myself, Zain, Mithunan and Arjun, and although our evidence is to be posted on separate blogs (and it is), I have posted my own copy o it on my as well. We finished 3 challenges:

1. We see 32 written slightly above 2. Our first guess was to type up 238 in the URL, however we were told to try something else by an error site which was eventually opened. So we eventually figured out the the reason for the 38 being above the 2 was because we wanted to find the 38th power of 2. So we figured out the answer to 2 ** 38 (274877906944) and entered it in the URL, which took us to the next challenge.

Screen Shot 2013-10-27 at 11.59.40

Screen Shot 2013-10-27 at 12.00.35

2. The next challenge involved cracking a code. The hint suggested we think TWICE, so we decided to translate the code given by going 2 letters higher each time. After entering this into the URL we realised it was’t the correct answer. So we looked again, and saw that the URL had the word ‘map’ in it. We went 2 letter higher on each letter of ‘map’ (‘ocr’), and we were taken on to the next challenge.

Screen Shot 2013-10-27 at 12.04.29Screen Shot 2013-10-27 at 12.04.41

To help with the efficiency of solving this challenge, I created a program in python which would do this for us:

Screen Shot 2013-10-29 at 23.25.17

 

This program refers each letter in a word to a dictionary and then increase the index of each letter in the word by 2, and refers the new index to the dictionary.

The output is as follows:

Screen Shot 2013-10-29 at 23.25.45

3. This challenge told us to look at the SOURCE of the page. I knew this was referring to the source code of the page. Here was a comment with a mess of random characters, and were told to find the rare characters in it. To my knowledge all the groups who attempted this challenge used the CONTROL+F browser function which looked up characters on the page. The word was ‘EQUALITY’.

Screen Shot 2013-10-27 at 12.33.19Screen Shot 2013-10-27 at 12.12.53Screen Shot 2013-10-27 at 12.37.12

However, I felt this method to be greatly inefficient, and I made a python program for this as well. This takes in the large string as input, and if the characters in the string were not in the alphabet (using the NOT IN function), we append the to a list, if they are in the alphabet we append them to another list. After iterating through the list we print out the list with the word in the alphabet which have been picked up. This give us the output of  [‘e’, ‘q’, ‘u’, ‘a’, ‘l’, ‘i’, ‘t’, ‘y’]. All the steps involved in my program are shown below:

1.Screen Shot 2013-10-27 at 12.35.11

2.Screen Shot 2013-10-27 at 12.38.283.Screen Shot 2013-10-27 at 12.38.49

18/10/13 – Decimal to Binary to Hexadecimal

Eventually Rohit and I finished our Denary to Binary converter. We also added another aspect to our code by which we convert the denary number to an equivalent Hexadecimal Value.

What is Hexadecimal?

Hexadecimal is a BASE 16 coding language, which is used alongside binary in the running of the computer. We see it used as a more user-friendly way of representing binary code, as it simplifies 4 binary bits to being 1 hexadecimal bit. We see Decimal Number being converted to Hexadecimal as shown in the table below (with all number from 1 – 10 the same in both Hex and Decimal, but numbers after 10 to 16 converting to letters from A to F).

670px-Convert-Hexadecimal-to-Binary-or-Decimal-Step-1

So how do we convert binary number to a hexadecimal:

  1. We split the binary number into groups of 4 (as 1 Hex bit is 4 Binary bits)
  2.  If any of the groups of 4 do not have enough numbers in them, we add on extra 0s to the beginning of the list without 4 bits in it (This process is shown below)629px-Convert-Binary-to-Hexadecimal-Step-3
  3. From here there are 2 ways to go about doing this:
  • We can either go through each group of 4 and convert them to their equivalent Hex counterpart, and if the Binary value is greater than 10 we can refer it to a dictionary.
  • Or we can find the Decimal form of each Binary Value and then divide it by 16 (due to Hex being a Base 16 number system). If they divide exactly then we base the first Hex number on the amount they divide by, and apply the same rule to its remainder.

Our Code

To solve this problem we began by making a simple piece of code to convert a Decimal Number to Binary:

Screen Shot 2013-10-20 at 18.00.45

 

To further convert the values to Hexadecimal we first had to make a dictionary with Hex Values from 10 to 16:

Screen Shot 2013-10-20 at 18.04.41

 

Finally we solved the problem using both logics explained above (and adding some extra variables – don’t worry if you don’t get it, I have posted the all of our work on my Google Sites page).

Method 1:

Screen Shot 2013-10-20 at 18.08.46

 

Method 2:

Screen Shot 2013-10-20 at 18.08.12

09/10/13 – Denary to Binary and Hexadecimal

Today we were given the task of converting a binary number to Denary. The initial task required us to print a number which only went up to 8 bits in equivalent Binary 1s and 0s. However Rohit and I felt this was too limiting and made the program pretty useless. So we decided to find a way of doing the same problem only being able to use any digits to get their binary equivalent.

When attempting to do this task in SCRATCH we were able to find some key issues with Scratch programming to understand how to run a code. As if you have prior programming knowledge you find it difficult to interpret the block of functions into more difficult functions and coding abilities. Therefore we decided to begin by doing the in python. The task was more difficult than we thought it would be, and took us 3 hours to make a Denary to Binary converter using logic functions of If, Else and Elif. Although we were aware of a much simpler method of Diving the binary number by its remainder when its divided by 2.

We have finished the Denary to Binary calculator part, however we are yet to complete the Denary to Hexadecimal part. We also intend to do alter our calculator further to allow it to convert Binary and Hexadecimal back to Denary. Using python graphics module, Rohit and I plan to put all of this into a console based system which will involve number entry like a calculator. Finally, we will interpret this all into Scratch, and I will post it on my blog.

However if you wish to see my Binary to Denary Calculator, feel free to ask me.

04/10/13 – Class Challenge

This week we did a class challenge to test our knowledge of what we had learnt over the past few weeks. The booklets consisted of a variety of logical thinking problems which we we have to solve using our knowledge of logic gates and problem solving. There were also some tasks on binary.

The challenge culminated in the making of a scratch program for a car park.

So in the case of my Scratch program (which I made with the help of my good friend Rohit), we have found a way of simulating a car park. So to begin with the car park randomly selects a number between 1 to 10, to tell us how many spaces it has in it. In a Forever loop, you are asked if you “Wish to Enter”, and if “The ticket has been issued,” and if the answer to both of them is “Yes” the barrier will open.

The most interesting bit about our Scratch program is after this, as we that when the barrier has opened, the car park loses 1 space. When the spaces in the car park eventually become 0, you are asked if “You wish to try another car park.” If the answer to this final question is no, the program stops, if the answer is Yes, the the program will randomly generate another number of space to simulate another car park, and then restart the loop!

Image

This wasn’t too complicated, so we decided to try to replicate this program in python using the same basic logic. Here is what we got: