Computer Science AS OCR
-
1-1-structure-and-function-of-the-processor as5 主题
-
1-2-types-of-processor as3 主题
-
1-3-input-output-and-storage as2 主题
-
2-1-systems-software as8 主题
-
2-3-software-development as5 主题
-
2-4-types-of-programming-language as4 主题
-
3-1-compression-encryption-and-hashing as3 主题
-
3-2-databases as3 主题
-
3-3-networks as8 主题
-
3-4-web-technologies as13 主题
-
html as
-
css as
-
css-styling as
-
javascript as
-
variables-and-constants-in-javascript as
-
outputs-in-javascript as
-
selection-in-javascript- as
-
for-loops-in-javascript- as
-
while-loops-in-javascript- as
-
strings-in-javascript- as
-
operators-in-javascript- as
-
nested-statements-in-javascript as
-
functions-and-procedures-in-javascript as
-
html as
-
4-1-data-types as8 主题
-
4-2-data-structures as4 主题
-
4-3-boolean-algebra as1 主题
-
5-1-computing-related-legislation as4 主题
-
5-2-moral-and-ethical-issues as9 主题
-
6-1-thinking-abstractly as3 主题
-
6-2-thinking-ahead as1 主题
-
6-3-thinking-procedurally as3 主题
-
6-4-thinking-logically as2 主题
-
6-5-thinking-concurrently as2 主题
-
7-1-programming-techniques as9 主题
-
8-1-standard-algorithms-and-big-o-notation as8 主题
logical-conditions-in-computational-thinking as
Exam code:H046
Determine the Logical Conditions that Affect the Outcome of a Decision
-
Most errors in a program occur when evaluating a Boolean condition, whether in a sequence as part of a statement, iteration or selection. It is therefore important to be careful when creating Boolean conditions, especially long, complex conditions involving multiple clauses
What are Boolean Conditions?
-
Boolean conditions use combinations of several operators:
-
== (equal to)
-
> (greater than)
-
>= (greater than or equal to)
-
< (less than)
-
<= (less than or equal to)
-
!= (not equal to)
-
AND (both conditions must be true)
-
OR (either or both conditions must be true)
-
NOT (the condition is not true)
-
XOR (only one or the other condition must be true)
-
-
An example of a condition could be a teenager wanting to see a 15 rated movie at a cinema that costs £8. If the teenager isn’t at least 15 years old and doesn’t have enough money then they cannot watch the movie
if age >= 15 and money >= 8 then
entry = True
endif
-
Another example could be checking whether a list contains any numbers and if so, removing them. In order to do this, each item must be checked one by one, checked to see if it is numeric then remove it if so
i = 0
valid_element = True
while len(my_list) > 0:
valid_element = True
element = str(my_list[i])
for index in list_item
if list_item[index] in [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] then
valid_element = False
break
endif
next index
if valid_element == False then
my_list.pop(i)
endif
endwhile
-
The above algorithm is a pseudocode solution to removing numbers from a list of strings
-
The decision points are:
-
While loop: the list has to have at least one element in order for the while loop to run
-
For loop: all elements in the list “list_item” are iterated over one at a time. The stopping condition is reaching the end of the list
-
First if statement: each character in the list “list_item” is checked. If it is a numeric digit then the string contains a number and therefore must be removed. Be aware that in this implementation, a string is considered numeric if it contains even a single digit. Valid_element is set to false and the program breaks out of the for loop
-
Be careful using “break” instructions. They are powerful and help control the flow of control but can be misused and cause unintended problems
-
Second if statement: if the item in “my_list” contains a digit, it is removed from the front of the list
-
-
Responses