Monday, 9 September 2013

Question 1. Don't Shout!

a) 














b) This problem is asking me to convert a message which is in upper case to lower case.

c) You will need to do the following:
1. You need to tell the computer what 'message' equals.
2. You need to use an input statement in order for it to know that you are using what is entered after 'Loud: ' to then convert into 'Quiet: '. 
3. You need to tell it to print 'Quiet: ' plus the message inputted in lower case form.

d) You need to remember a few things that were taught previously.

- Input: asking the user for input: Week 1 Module 1

- Print: Week 1 Module 1 - Changing cases: Week 2 Module 2

e) My attempts:
























This was my first attempt. I received a syntax error pointing at the empty brackets. I then looked back on how to change the text to lower case and I discovered my mistake. I needed to put message.lower(). 



























This was my second attempt. I applied my corrections and I ran the program to test it. I entered a message in upper case and then hit enter which then converted the message to lower case. Since this is what the brief was, I decided to mark my work.




This was my final results and my code worked!

f) My main error was working out how to change the message into lowercase. I needed to look back on previous examples given in order to complete the problem. 



g)

My Code:



h) The sample solution and my solution are basically the same. 
The differences are:
- I used " instead of '
- I used a + instead of a ,
- I used the word 'message' they used 'line'
These differences do not make a difference in the outcome. They are only slight and are not apparent in the outcome. I was marked correctly so they must not have mattered. 


Question 2. 'Access Denied'

Access Denied:

a)


b) This problem is asking me to write a program which only grants access if the password is correct. It is asking that if anything else is entered, for it to print access denied.


c) For this question, you need to break it down into sections. 
1. You need to tell the computer what 'password' equals.
2. You need to make an 'if' statement equalling 'chEEzburg3rz' 
3. Then you need to tell it to print 'Access granted' 
4. You then need to make an 'else' statement 
5. Finally you need to tell it to print 'Access denied' in order to make sure that if anything else apart from the correct password is entered, you do not receive access. 

d) You need to remember a few things that were taught previously.

- Input: asking the user for input: Week 1 Module 1

- Print: Week 1 Module 1

- 'if' statements: Week 2 Module 1

- 'else' statements: Week 2 Module 1

e) My attempts:









So in this attempt, I reached a syntax error. It was pointing to my equals sign. So I figured that I needed to add another equals sign in, as I had previously read about.

























I tried the exact same code, just using a double equals sign. I didn't get a syntax error so I tried it out and it worked with the correct password.



So I then tried with an incorrect password and it also worked. So I decided to mark my code.


My code was correct! 


f) My main source of error was just realising that I needed to use a double equal sign.
Also I had to figure out how to successfully use 'if' and 'else' statements.


g)

h) This solution provided by grok is almost the exact same as my solution. The only difference is that I used another set of brackets to enclose everything on the first line after the equals sign. That set of brackets proved to be unnecessary. Both my solution, and the sample solution work perfectly fine. The sample solution however is slightly more elegant as it is slightly less busy.