Back to 课程

Computer Science GCES EDEXCEL

0% Complete
0/0 Steps
  1. Decomposition And Abstraction Edexcel
    2 主题
  2. Algorithms Edexcel
    11 主题
  3. Truth Tables Edexcel
    3 主题
  4. Binary Edexcel
    6 主题
  5. Data Representation Edexcel
    4 主题
  6. Data Storage And Compression Edexcel
    2 主题
  7. Hardware Edexcel
    5 主题
  8. Software Edexcel
    3 主题
  9. Programming Languages Edexcel
    2 主题
  10. Networks Edexcel
    7 主题
  11. Network Security Edexcel
    2 主题
  12. Environmental Issues Edexcel
    1 主题
  13. Ethical And Legal Issues Edexcel
    3 主题
  14. Cybersecurity Edexcel
    2 主题
  15. Develop Code Edexcel
    6 主题
  16. Constructs Edexcel
    4 主题
  17. Data Types And Data Structures Edexcel
    5 主题
  18. Operators Edexcel
    1 主题
  19. Subprograms Edexcel
    2 主题
课 Progress
0% Complete

Exam code:1CP2

What is a Programming Concept?

  • A programming construct determines the order in which lines of code are executed

  • They control the logic and behaviour of code

  • There are four core programming constructs:

    • Sequence

    • Selection

    • Iteration

    • Repetition

Sequence

What is a sequence?

  • Sequence refers to lines of code which are run one line at a time

  • The lines of code are run in the order that they are written from the first line of code to the last line of code

  • Sequence is crucial to the flow of a program, any instructions out of sequence can lead to unexpected behaviour or errors

Example

  • A simple program to ask a user to input two numbers, number two is subtracted from number one and the result is outputted

Line

Pseudocode

01

print("Enter the first number")

02

Num1 = input()

03

print("Enter the second number")

04

Num2 = input()

05

Result = Num1 - Num2

06

print(Result)

  • A simple swap of line 01 and line 02 would lead to an unexpected behaviour, the user would be prompted to input information without knowing what they should enter

Selection

What is selection?

  • Selection is when the flow of a program is changed, depending on a set of conditions

  • The outcome of this condition will then determine which lines or blocks of code are run next

  • Selection is used for validation, calculation and making sense of a user’s choices

  • There are two ways to write selection statements:

    • if… then… else… statements – this is when you test conditions sequentially 

    • case select or switch… statements – this is when you test an expression against multiple possible constant values (known as cases)

if-else-if-else-statement-pseudocode-computer-science-revision-notes

Example

Concept

Python

IF-THEN-ELSE

if answer == "Yes": print("Correct")
elif answer == "No": print("Wrong")
else: print("Error")

Repetition

What is repetition?

  • Repetition is repeating a line or a block of code using a loop

  • Repetition can be:

    • count controlled – this is when the code is repeated a fixed number of times (e.g. using a for loop)

    • condition controlled – this is when the code is repeated until a condition is met (e.g. using a while loop or a do while loop)

Count controlled

xp66-srn-for-loop-pseudocode-computer-science-revision-notes

Condition controlled

while-loop-password-pseudocode-computer-science-revision-notes

Examples

Repetition

Python

FOR loop

(Count controlled)

for x in range(10): print("Hello")

This will print the word “Hello” 10 times (0-9 inclusive)

for x in range(2,12,2): print(x) # Python range function excludes end value

This will print the even numbers from 2 to 10 inclusive

for x in range(10,-1,-1): print(x) # Python range function excludes end value

This will print the numbers from 10 to 0 inclusive

WHILE loop

(Condition controlled)

while colour != "Red": colour = input("New colour")

 

This will loop until the user inputs the colour “Red”. Check condition is carried out before entering loop

Iteration

What is Iteration?

  • Iteration is going over every item in a data structure

  • An example of this would be searching through a list to find an item within the list

  • If a list was not sorted, a linear search may be used

Python code for a linear search
Linear Search in Python
  • On line number 7, you can see where iteration takes place as it uses a for loop to iterate through the list of numbers to see if the number 1 is present

Worked Example

Tick (✓) one box in each row to identify whether each programming construct has or has not been used in the program [3]

total = 0
for i in range (1,5): num = input("Enter a number") total = total + num
print(total)

<t

Has been used

Has not been used

Sequence

 

 

Selection

 

 

Iteration

 

 

Repetition

Responses

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