Thursday 16 July 2015

A Wee Python Challenge

A Wee Python Challenge


In today's lesson we are going to start with a mini Python challenge.

Your Task:

Answer the two problems below.

Screen dump the code and the output to a Google document and post the URL to the blog.

NOTE:  If you get help from another website or a peer acknowledge this under a heading called 'Sources'.

Problems

1. Write a program in Python which adds up 3 numbers which are inputted by the user.

2. Write a program in Python which finds the maximum number in the list below:

[7,15,4,5,22,32,45,19]

When you have finished the challenge you may continue with the Controlled assessment work:

Extension Challenge (Optional but worth doing for CA)

Write a Python Program for a 'Tic Tac Toe' game.  This is quite a big program and you may want to reserach and try it out as an additional task over the Summer.

.


Thursday 9 July 2015

Controlled Assessment/Summer Work

Controlled Assessment/Summer Work


Platinum 

(1) Complete all three questions according to the brief.

(2) Screen dump, code, testing plans and evaluations into one carefully laid out google doc.

(3) Reply to this post with a link to your google.doc by 1st September 2015

Gold

(1) Complete Question 3 and check against code.

(2) In a google.doc show a copy of your code and your test plan.

(3) Reply to this post with a link to your google.doc by 1st September 2015

Silver

(1) Carefully examine the code for Q3.  Copy into a google doc and annotate explaining carefully what each section of code does..

(2) Write an algorithm explaining what the code does.

(3) Reply to this post with a link to your google.doc by 1st September 2015


Materials 

(1) Click on the link below for the question exemplar paper:

http://qualifications.pearson.com/content/dam/pdf/GCSE/Computer%20Science/2013/Specification%20and%20sample%20assessments/GCSE_in_Computer_Science_SCAM_TYPESET.pdf

(1) Click on the link below for the example of the code for Q1.

https://docs.google.com/document/d/1tJvvPQh4N0-pYAT00D4iXFeknFPrN-tHTAL5DkKWvyY/edit

(2) Click on the link below for the example of the code for Q2.

https://docs.google.com/document/d/1Qud2jkxJPUsb2Sb38F6YRVFtUekEYxgKWNSHiRTzWw4/edit

Click on the link below for an example of the testing plan for Q2

https://docs.google.com/document/d/1uIle_JzzYJA3APJYVxrhiCyvprLlswKyVNGi-ERMlAQ/edit

(3) Click on the link below for the example of the code for Q3.

https://docs.google.com/document/d/1PqUT3WSqjehsZeLF6n6XqivmqgDhaiCWdochLJwY2Zc/edit


Click on the link below for an example of the testing plan for Q2

https://docs.google.com/document/d/10hb9Z9EBkKLpde7ZuP_Fs5BLII3hGhR7jFoc_cFFQt0/edit

Click on the link below for Player Scores txt file.


https://drive.google.com/file/d/0B094zD02-dLYY3NveEpRWUtCNXM/view?usp=sharing

New GCSE Computing Python Course

Please note that this course is curently a work in progress:

https://docs.google.com/document/d/1mqifndp7CFsrSnQuKL90adZinM-InJSAc4nKJXWWlk0/edit

Don't forget the superb 'Invent With Python Book' that you can go through online:

https://inventwithpython.com/chapters/

Also, make sure that you have completed the CodeCademy Python course:

http://www.codecademy.com/en/tracks/python

Finally, 'Computer Science Circles' is another excellent online tutorial:

http://cscircles.cemc.uwaterloo.ca/



Monday 6 July 2015

Summer 2015 Work

Exam Feedback and Summer Work

6th July lesson:

Starter

1. In your notebook write a heading 'Exam Feedback'. 

2. Model of a computer system: draw the INPUT/PROCESS/OUTPUT - STORAGE

3. Data types: Please list five types of data:

4.In a database field called 'surname' give evidence two lots of test data for a type check.

5. .In a database field called 'date_of_birth' give evidence two lots of test data for a type check.

Summer Python Work

Complete Question 3 from the exemplar below and submit:

http://qualifications.pearson.com/content/dam/pdf/GCSE/Computer%20Science/2013/Specification%20and%20sample%20assessments/GCSE_in_Computer_Science_SCAM_TYPESET.pdf

2015/16

A link to a new Python Course will be posted here shortly:







Wednesday 1 July 2015

15. Pseudocode and built-in subprograms: random function






Activity 14.1
Pseudocode
Pseudocode, or ‘mock’ code, is another way of describing a program. You will need a copy of the pseudocode used in this course (Appendix B of the specification) to answer thesequestions.

What does this pseudocode do?
RECEIVE myName FROM (STRING) KEYBOARD
RECEIVE myAge FROM (INTEGER) KEYBOARD
SET AgeInTen TOmyAge + 10
SEND myName “will be” AgeInTen “in 10 years time” TO DISPLAY

Write the Python code for this program.
Activity 14.2
What does this pseudocode do?
SET score TO 119
IF score < 50 THEN SEND “You have lost” TO DISPLAY
ELSE SEND “You have won” TO DISPLAY
END IF

Write the Python code for this program.
Activity 14.3
random() function
Copy and run this program code:

Run the program a few times. What does it do?
What is meant by ‘import random’?
What happens if you alter the values to 1, 100?
Activity 14.4
Write a program that acts like a dice. After each ‘throw’ of the dice it should ask if the playerwishes to continue and stop when they enter ‘Y’.
Activity 14.5
Write a program that gives the user 10 chances to guess a number between 1 and 10. It then compares their answer with a randomly generated number and stops the program when the number generated matches the number guessed or when the user is out of guesses.

14. Repetition construct: while loop, flowcharts






Activity 13.1
While command
What does this while command do?
What is the condition that is being tested and how does it change?
Activity 13.2
Write a program that asks the user if they are hungry. While they reply ‘N’ the program repeats the question, showing how many times they have replied ‘N’.  
When they reply ‘Y’, the program tells them to get something to eat.
Activity 13.3
What does this program do?
What is the ‘sentry’ variable?
What is the condition?
Activity 13.4
Flowcharts and while command
Flowcharts can be used to represent programs. Complete the flow chart for this program.

12. Data structures: lists (arrays), using Python docs






It also allows you to choose how to format the output.
Lesson 11 activities
Activity 11.1
Lists (arrays)
Complete this table to summarise the list commands.
Things to do with lists
Commands
Create a list

Reference an item in a list

Delete an item in a list

Append an item to the end of a list

Activity 11.2
Lists (arrays)
A list is a data structure that stores a set of elements. Lists are assigned to a name using square brackets.

>>>mylist=["apple","oranges","lemon","pear","lime"]

apples
oranges
lemon
pear
lime
0
1
2
3
4

Each element in a list has an index location. The first element of the list is in position zero (0).

Elements of a list are referenced using their index location (an integer number).
List name[index]

A range of elements can be displayed using
[start index: end index]

Start index is the position to start at (remember that indexing starts at zero)End position is the index AFTER the index required.

Make this list and experiment with the list commands.
>>>mylist=["apple","orange","lemon","pear","lime"]

What does mylist[1] display?
What does mylist[1:3] display?
What does mylist[-1] display?
What command will display just apple?
What command will display lemon and pear?

Make a new list called myfood containing your five favourite foods.
Display the whole list.
Display the food item at index position 3.
Display the food item at index position 0.
Display the food items at index position 1 to 4.
Activity 11.3
Using lists
Make the list that contains the class marks for Amy Jones.

Marks = ['Amy', 'Jones', 'English', 67, 'Maths', 76, 'Computer Science', 96]

The English teacher has entered Amy’s mark incorrectly; it should be 72 not 67. Alter this item in the list.
Add the mark for Physics to the end of the list.  “Physics”, 65
Remove “Maths” and the score 76 from the list.
Write a program to find the average score for the three subjects (English, Computer Science and Physics).
Activity 11.4
Using Python docs help
Select help/python docs then select the Python tutorial and go to 3.1.4 Lists.
Read through the discussion of lists and try out the examples. Make a note of three more facts about lists to share in the next lesson.
Python is a very powerful programming language which is used in universities and commercial organisations. You do not need to know all the details provided in the Python docs but, with practice, you should be able to find information about Python that can be very useful.Lesson 12 activities

11. Data types: string manipulation and string methods


You will learn:
  • To use strings
  • To use index positions in strings
  • To slice strings


Activity 10.1
Strings
Write the index position for each character in the string.
H
e
l
l
o

w
o
r
l
d
!













What character is at index 3?
What character is at index 5?
What character is at index 0?
What character is at index 11?
How many characters are there in this string?
Activity 10.2
Use the interactive shell to explore how strings can be concatenated.
Make a variable called FirstName and set its value to the string “Fred
Make a variable called SecondName and set its value to the string “Smith”
Make a variable called FullName and set its value to the value of the variablesFirstName plus SecondName
Print the value of the variable FullName

Activity 10.3
Slicing strings
Parts of a string can be extracted (or sliced) by giving the index location in the format:
[start position: end position]

Start position is the index at which the slice starts (remember that indexing starts at zero).End position is the index AFTER the last index required.

Use the interactive shell to explore how strings can be sliced.

Make a variable called word and set its value to the string “PIZZA”.

>>>word="PIZZA"

P
I
Z
Z
A
0
1
2
3
4

 
What do these commands do?

o
>>>word[2:5]
o
>>>word[1:2]
o
>>>word[0:3]
o
>>>word[0:5]

Hint: Remember that the index starts at zero not one.
Activity 10.4
A variable has been created and assigned the string “watch #bbcclick today”

myVariable = “watch #bbcclick today”

w
a
t
c
h

#
b
b
c
c
l
i
c
k

t
o
d
a
y
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

What command would you use to extract the following slices?

o
#bbcclick
o
watch
o
today

Check your answers using the interactive shell.
Activity 10.5
Using string methods
Any variable with a string assigned is a member of the class called string. String methods can be used to manipulate that string.
Explore string methods by working through these commands in the interactive shell and describing what happens.

>>>myVariable="There's a starman waiting in the sky"
>>>myVariable.upper()
>>>myVariable.replace("a","x")
>>>myVariable.title()
>>>myVariable.swapcase()
Activity 10.6
The string .format method revisited: using the string .format method to format output
There are two ways to output information to the screen. Using the print() function or by giving the expression.

Try these now:
>>>myName="David Bowie"
>>>print(myName)
David Bowie

 >>>myName
'David Bowie'

The string .format is used to give more control over formatting.

It allows you to use placeholders and then specify the variable you want to print in the string. The placeholders are shown using {}.

>>>first="David"
>>>second="Bowie"
>>>print("The best music is from {0}       {1}!".format(first,second))

The best music is from David       Bowie!

It also allows you to choose how to format the output.