subject computer science course a-level awarding body ocr...a level computer science – yr12...

15
This research based project is designed to give you an ideal grounding for your A Level Computer Science course. Research and complete the tasks independently over the summer to get a head start and prepare for the key topics within Year one of A Level Computer Science. Subject Computer Science Course A-Level Awarding Body OCR

Upload: others

Post on 01-Jun-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

This research based project is designed to give you an ideal grounding for your A Level Computer Science

course. Research and complete the tasks independently over the summer to get a head start and prepare for

the key topics within Year one of A Level Computer Science.

Subject Computer Science

Course A-Level

Awarding Body OCR

Page 2: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 2 of 20 The Redhill Academy

Programming Skills Development – TKinter User Interface

Use these worksheets to develop your skills in the use of TKinter to create programs that run from a

Graphical User Interface (GUI).

Check each task off when you have completed them.

Grid Method

Temperature Converter Program ❑

BMI Program ❑

File Menu Program ❑

Place Method

File Handling Names and Ages Program ❑

Make sure you save all programs and bring them into school. The code you produce will be

invaluable when developing further programs during the A Level Computer Science course.

Non-TKinter Programming

Bubble Sort ❑

Insertion Sort ❑

Note: See resource notes

Completed ‘Tell me about yourself’ task ❑

Page 3: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 3 of 20 The Redhill Academy

A Level Computer Science

Python GUI Programming

Temperature Converter

Task

Design a program that will convert any input temperature to C or F.

GUI

Design Grid

Columns

0 1 2 3

Ro

ws

0

1 Label

Temperature Entry Text Box

ttktemperature

2 Label

Converts To

Label Degrees F or C

3 Button Clear

Button

Calculate Celcius

Button Calculate

Farenheight

There are no form objects in row 0 on the grid.

Row 1 has two items: a label showing Temperature and a Text Entry Box

Row 2 has two items: A label saying Converts To (column 0) and either Degrees Farenheight or Degree Celcius

is displayed in a Label in column 2.

Row 3 has three items: A Clear button, A Calculate Celcius button in column 2 and a Calculate Farenheight

button in column 3

This should help you understand the grid property of the python program.

Think of frame1 in the code as being the entire design table above.

The formula to convert temperature from degrees farenheight to celcius is:

C = (F – 32) ÷ 1.8

The formula to convert temperature from degrees celcius to farenheight is:

F = (C * 1.8) + 32

Page 4: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 4 of 20 The Redhill Academy

Task - Python Code

Enter this python code into the python text editor carefully. Any slight mistake and the python output window

will display nothing and give an error.

Page 5: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 5 of 20 The Redhill Academy

A Level Computer Science - Python GUI Programming

BMI Calculator

Task

Design a program that will calculate someone’s BMI given their height in metres and weight in kg.

GUI

Design Grid

Columns

0 1 2 3

Ro

ws

0

1 Label

Enter Height Entry Box

Height

2 Label

Enter Weight Entry Box

Kg

3 Button

Calculate Button Clear

4 Label

Your BMI Label

Calculated BMI Label

Category Label

Category

There are no form objects in row 0 on the grid.

Row 1 has two items: a label Asking for Height and a Text Entry Box

Row 2 has two items: A label Asking for Weight and a Text Entry Box

Row 3 has two items: A Clear button and A Calculate BMI button

Row 4 has four items: A label for Your BMI, A label for calculated BMI, A label for Category and a Label for the

calculated category

This should help you understand the grid property of the python program.

Think of frame1 in the code as being the entire design table above.

The program then calculates the BMI (Body Mass Index) using the formula:

BMI = weight ÷ height The formula has two steps! BMI = BMI ÷ height

IF BMI is greater than 30 then category displayed is Obese. See other categories below.

IF BMI is greater than 19.5 and less than 25 then the category displayed is Overweight.

Page 6: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 6 of 20 The Redhill Academy

Task - Python Code Enter this python code into the python text editor carefully. Any slight mistake and the python output window

will display nothing and give an error.

Note: The programming code on this document is small but you can zoom into see it larger.

Run the program and check that it works correctly. A height of 1.7m and a weight of 86Kg should be

categorised as Overweight.

Page 7: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 7 of 20 The Redhill Academy

A Level Computer Science - Python GUI Programming

File Menu

Task

Design a program that will create the typical options of Software Application drop down file system

(WIMP – Windows Icon Menu Pointers) Environment.

GUI

Task - Python Code Enter this python code into the python text editor carefully. Any slight mistake and the python output window

will display nothing and give an error.

Run and test the program with particular attention to file open.

Add this new form widget to one of the tools you might want to use in future programs.

Page 8: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 8 of 20 The Redhill Academy

A Level Computer Science

Using Images in TKinter – File Handling – Names and Ages

Scenario - Create a python program that uses a Tkinter GUI interface to capture the names and ages of

people. A complete list of all names and ages saved should be displayed in a list box.

Task 1

Enter the following program code(on page 2) into a python editor. Make sure that it contains no typing errors.

This task is just to teach (using the code comments) how you can display images using python.

Note: The csv file will be given to you

Make sure you save your python program and the csv file in the same folder.

Task 1

Create a window that will ask the user to enter a number in a text entry box. When they click on a button it

will use the code

variable.isdigit()

to check to see if it is a whole number. If it is a whole number, add it to the list box, otherwise clear the entry

box. Add another button that will clear the list.

listbox.delete(0, END) can be used to clear a list box contents

Task 2

Alter the program in Task 1 to add a third button that will save the list to a csv file. The code

temp_list = num_list.get(0, END)

can be used to save the contents of a list box a tuple called tmp_list.

Note: Tuple Definition

This is an important word for A Level Computer Science. A tuple means a data structure consisting of multiple

parts. In the example code the tuple is new_record because it has two parts, name and age.

Page 9: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 9 of 20 The Redhill Academy

Example Program Code

Page 10: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy

The bubble sort orders an unordered list of items by comparing each item with the next one and swapping them if they are out of order. The algorithm is finished when no swaps are made. It effectively “bubbles up” the largest (or smallest) item to the end of the list. Bubble sort in simple-structured English 1. Start at the first item in the list. 2. Compare the current item with the next one. 3. If the two items are in the wrong position, swap them. 4. Move to the next item in the list. 5. Repeat from step 2 until all the unsorted items have been compared. 6. If any items were swapped, repeat from step 1. Otherwise, the algorithm is complete. Stepping through the bubble sort

Index: 0 1 2 3 4

Step 1 Compare Florida and Georgia. No swap needed

→Florida Georgia← Delaware Alabama California

Step 2 Compare Georgia and Delaware. Swap the items.

Florida →Georgia Delaware← Alabama California

Step 3 Compare Georgia and Alabama. Swap the items.

Florida Delaware →Georgia Alabama← California

Step 4 Compare Georgia and California. Swap the items.

Florida Delaware Alabama →Georgia California←

Step 5 Georgia has been bubbled to the end of the list. Start the algorithm again because at least one swap was made.

Compare Florida to Delaware. Swap the items.

→Florida Delaware← Alabama California Georgia

Step 6 Compare Florida with Alabama. Swap the items.

Delaware →Florida ←Alabama California Georgia

Step 7 Compare Florida with California. Swap the items.

Delaware Alabama →Florida California← Georgia

Step 8 Florida has bubbled to the end of the list. Start the algorithm again because at least one swap was made.

Compare Delaware with Alabama. Swap the items

→Delaware Alabama← California Florida Georgia

Step 9 Compare Delaware with California. Swap the items.

Alabama →Delaware California← Florida Georgia

Step 10 Delaware has bubbled to the end of the list. Start the algorithm again because at least one swap was made.

Compare Alabama with California. No swap needed.

→Alabama California← Delaware Florida Georgia

Step 11 No swaps were made. The list is sorted.

Alabama California Delaware Florida Georgia

Page 11: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 11 of 20 The Redhill Academy

Pseudocode for bubble sort items = [“Florida”,”Georgia”,”Delaware”,Alabama”,”California”] n -= items.Length swapped = True While n > 0 AND swapped swapped = False n = n - 1 For index = 0 TO n - 1 If items[index] > items[index+1] then Swap(items[index], items[index +1]) Swapped = True End If End For End While Bubble sort coded in Python Items = [“Florida”,”Georgia”,”Delaware”,Alabama”,”California”] n = len(items) swapped = True while n > 0 and swapped == True: swapped = False n = n - 1 for index in range(0,n): if items[index] > items[index+1]: temp = items[index] items[index] = items[index+1] items[index+1] =temp swapped = True #Output the result Print(items)

Sorting Task 1

Type the above code into python and write about how the code performs a complete bubble sort in your own

words.

Page 12: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 12 of 20 The Redhill Academy

Efficiency of bubble sort

Time complexity Space complexity Best

case Average

case Worst case

O(n) O(n2) O(n2) O(1)

Linear Polynomial Polynomial Constant

In the best case, the data is already ordered – in which case, only one pass is required to check all the items in the list and no swaps will be made. Therefore, it is of linear complexity: O(n). This is not usually the case, as the purpose of the algorithm is to sort data. As the algorithm contains a nested loop, it usually has polynomial complexity – O(n2) – because the time it takes to execute both iterations increases with the size of the data set. However, it does not require any additional memory. It can be performed on the data structure containing the data set, so the space complexity is O(1). The most efficient method of implementing a bubble sort stops the algorithm when no swaps are made. Although this is not necessary, it is preferable and reduces execution time.

Page 13: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 13 of 20 The Redhill Academy

The insertion sort inserts each item into its correct position in a data set one at a time. It is a useful algorithm for small data sets. Insertion sort in simple-structured English 1. Start at the second item in the list. 2. Compare current item with the first item in the sorted list. 3. If the current item is greater than the item in the list, move to the next item in the sorted list. 4. Repeat from step 3 until the position of the current item is less than or equal to the item in the sorted list. 5. Move all the items in the list from the current position up one place to create a space for the current item. 6. Insert the current item. 7. Repeat from step 2 with the next item in the list until all the items have been inserted. Stepping through the insertion sort

Index: 0 1 2 3 4

Step 1 Start at the second item (index 1): Georgia

Compare Georgia with the first item: Florida.

→Florida Georgia← Delaware Alabama California

Step 2 Georgia is greater than Florida. It is in the correct place. Move to the next item: Delaware.

Compare Delaware with the first item on the list: Florida

→Florida Georgia Delaware← Alabama California

Step 3 Delaware is less than Florida. Insert before Florida. Move to the next item: Alabama

Compare Alabama with the first item in the list: Delaware.

→Delaware Florida Georgia Alabama← California

Step 4 Alabama is less than Delaware. Insert before Delaware. Move to the next item: California

Compare California with the first item in the list: Alabama.

→Alabama Delaware Florida Georgia California←

Step 5 California is greater than Alabama. Check the next item: Delaware.

Alabama →Delaware Florida Georgia California←

Step 6

California is less than Delaware. Insert California.

Alabama Delaware Florida Georgia California←

No more items in the list to check. Sort complete.

Pseudocode for insertion sort items = [“Florida”,”Georgia”,”Delaware”,”Alabama”,”California”] For index = 1 TO items.Length Index2 = index - 1 While index2 > 0 AND items[index2 -1] > items[index] items[index2] = items[index2 -1] index2 = index2 -1 End while Intems[index2] = items[index] End For

Page 14: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 14 of 20 The Redhill Academy

Insertion sort coded in Python items = [“Florida”,”Georgia”,”Delaware”,”Alabama”,”California”] n = len(items) for index in range(1,n): current = items[index] index2 = index while index2 > 0 and items[index2 -1] > current: items[index2] = items[index2 -1] index2 = index2 -1 items[index2] = current #Output the result print(items) Efficiency of the insertion sort

Time complexity Space complexity Best

case Average

case Worst case

O(n) O(n2) O(n2) O(1)

Linear Polynomial Polynomial Constant

In the best case, the data set is already ordered, so no data needs to be moved. The algorithm has a linear time complexity – O(n) – since each item must still be checked. This is not usually the case, as the purpose of the algorithm is to sort data. The algorithm contains a nested iteration – one loop to check each item and another to move items so that an item can be slotted into place. Due to these iterations, the algorithm has polynomial complexity: O(n2). The algorithm does not require any additional memory, as it can be performed on the data structure containing the data set. Therefore it has a space complexity of O(1). An alternative version of the algorithm puts sorted data into a new list instead of working on the original list. This does not change the time complexity of the algorithm but would increase the space complexity to O(n).

Sorting Task 2

Type the above code into python and write about how the code performs a complete insertion sort in your

own words.

Created by Mr P Stevens 31-5-2020

Page 15: Subject Computer Science Course A-Level Awarding Body OCR...A Level Computer Science – Yr12 Bridging Unit Page 10 of 20 The Redhill Academy The bubble sort orders an unordered list

A Level Computer Science – Yr12 Bridging Unit Page 15 of 20 The Redhill Academy

Why did you choose Computer Science?

In this simple task you get the opportunity to tell me your choices and reasons behind choosing to study

Computer Science. Please answer all questions as best you can.

1. Why did you choose to study A Level Computer Science?

2. What other courses have you chosen to study at Key Stage 5, and what made you choose this

combination?

3. What are you hoping to achieve from studying Computer Science?

4. How would you describe yourself as a learner at GCSE? What skills where you good at, what areas would

you like to improve on?

5. What are your other hobbies and interests outside of school? Anything related to Computing?