Back to 课程

Computer Science GCES OCR

0% Complete
0/0 Steps
  1. Cpu Architecture Performance And Embedded Systems Ocr
    5 主题
  2. Primary And Secondary Storage Ocr
    6 主题
  3. Data Storage And Compression Ocr
    12 主题
  4. Networks And Topologies Ocr
    6 主题
  5. Wired And Wireless Networks Protocols And Layers Ocr
    6 主题
  6. Identifying And Preventing Threats To Computer Systems And Networks Ocr
    2 主题
  7. Operating Systems And Utility Software Ocr
    2 主题
  8. Ethical Legal Cultural And Environmental Impact Ocr
    2 主题
  9. Computational Thinking Searching And Sorting Algorithms Ocr
    3 主题
  10. Designing Creating And Refining Algorithms Ocr
    5 主题
  11. Programming Fundamentals And Data Types Ocr
    5 主题
  12. Additional Programming Techniques Ocr
    7 主题
  13. Defensive Design And Testing Ocr
    6 主题
  14. Boolean Logic Diagrams Ocr
    2 主题
  15. Programming Languages And Integrated Development Environments Ides Ocr
    3 主题
  16. The Exam Papers Ocr
    2 主题
  17. Structuring Your Responses Ocr
    3 主题
课 Progress
0% Complete

Exam code:J277

Taking an algorithm and turning it into code, in any language, requires an understanding of several basic programming concepts such as:

  • Variables

  • Constants

  • Assignment

  • Operators

  • Inputs

  • Outputs

Variables, Constants & Assignments

What is a variable?

  • A variable is a named memory location that holds data that during the execution of a program, the data can change

  • Variables can store a variety of different types of data such as numbers, text or true/false values

  • To store data in a variable, the process of assignment is used

What is a constant?

  • A constant is fixed data that during the execution of a program cannot change

  • A constant can store a variety of different types of data, similar to variables

  • Pi is an example of a mathematical fixed value that would typically be stored as a constant

What is assignment?

  • Assignment is the process of storing data in a variable or constant under a descriptive name

  • Assignment is performed using the ‘=‘ symbol

Assigning variables & constants

Concept

OCR exam reference

Python

Variables

x = 3

name = "Save My Exams"

x = 3

name = "Save My Exams"

Constants

const vat = 0.2

const pi = 3.142

VAT = 0.2
PI = 3.142

Operators, Inputs & Outputs

What is an operator?

  • An operator is a symbol used to instruct a computer to perform a specific operation on one or more values

  • Examples of common operators include:

    • Arithmetic

    • Comparison

    • Boolean (AND, OR and NOT)

Arithmetic

Operator

OCR exam reference

Python

Addition

+

+

Subtraction

-

-

Multiplication

*

*

Division

/

/

Modulus (remainder after division)

MOD

%

Quotient (whole number division)

DIV

//

Exponentiation (to the power of)

^

**

Comparison

Operator

OCR exam reference

Python

Equal to

==

==

Not equal to

!=

!=

Less than

<

<

Less than or equal to

<=

<=

Greater than

>

>

Greater than or equal to

>=

>=

Examples

Operator

OCR exam reference

Python

Addition

sum = 2 + 2 # 4

sum = 2 + 2 # 4

Multiplication

sum = 3 * 4 # 12

sum = 3 * 4 # 12

Modulus

sum = 10 MOD 3 # 1

sum = 10 % 3 # 1

Quotient

sum = 10 DIV 3 # 3

sum = 10 // 3 # 3

Exponentiation

sum = 2 ^ 2 # 4

sum = 2 ** 2 # 4

Equal to

if 3 == 3 then # True

if 3 == 3: # True

Not equal to

if 5 != 6 then # True

if 5 != 6: # True

Greater than or equal to

if 10 >= 2 then # True

if 10 >= 2: # True

AND

number = 10
if number > 0 and < 20 then
# True

number = 10
if number > 0 and number < 20:
# True

What is an input?

  • An input is a value that is read from an input device and then processed by a computer program

  • Typical input devices include:

    • Keyboards – Typing text

    • Mice – Selecting item, clicking buttons

    • Sensors – Reading data from sensors such as temperature, pressure or motion

    • Microphone – Capturing audio, speech recognition

  • Without inputs, programs are not useful as they can’t interact with the outside world and always produce the same result

What is an output?

  • An output is a value sent to an output device from a computer program

  • Typical output devices include:

    • Monitor – Displaying text, images or graphics

    • Speaker – Playing audio

    • Printer – Creating physical copies of documents or images

Area of a rectangle program

OCR exam reference

# Get the length and width from the user
length = input("Enter the length of the rectangle: ")
width = input("Enter the width of the rectangle: ") # Calculate the area
area = length * width # Check if the area is greater than 100
if area > 100 then # Print the results print("The area of the rectangle is", area)
endif

Python

# Get the length and width from the user
length = int(input("Enter the length of the rectangle: "))
width = int(input("Enter the width of the rectangle: ")) # Calculate the area
area = length * width # Check if the area is greater than 100
if area > 100: # Print the results print("The area of the rectangle is", area)

Worked Example

A cinema calculates ticket prices based on age category

  • Adult = £13.00

  • Child = £7.50

The program asks the user to enter their age and calculates the cost of their ticket

A simple algorithm is used

adult = 13.00
child = 7.50
age = input("What is your age: ")
if age > 18 then total_cost = adult
else total_cost = child
end if
print(total_cost)

The cinema decides to add a discount of 25% to customers who come to the cinema on ‘Sunday evening’

Identify all the additional inputs that will be required for this change to the algorithm [2]

How to answer this question

  • What new information is needed?

Answer

  • day

  • time

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注