Computer Science 1
Computer Science 1
Question 1
Solution 1
Pseudocode:
START
length = INPUT "Enter the length of the rectangle:"
width = INPUT "Enter the width of the rectangle:"
perimeter = 2 * (length + width)
OUTPUT perimeter
STOP
Question 2
START
radius = INPUT "Enter the radius of the circle:"
area = 3.14 * radius * radius
OUTPUT area
STOP
Solution 2
Flowchart Steps:
Question 3
Solution 3
Pseudocode:
START
salary = INPUT "Enter your monthly salary:"
bonus = salary * 0.15
OUTPUT bonus
STOP
--
Question 4
Using the pseudocode from Question 3, calculate the bonus if the salary is
$5,000. Show your working.
Solution 4
Working:
Bonus = $5,000 * 0.15 = $750
Output: Bonus = $750
Question 5
Write a pseudocode that asks a user if it is raining. If the user inputs "Yes,"
output "Take an umbrella." Otherwise, output "No umbrella needed."
Solution 5
Pseudocode:
START
isRaining = INPUT "Is it raining? (Yes/No):"
IF isRaining = "Yes" THEN
OUTPUT "Take an umbrella."
ELSE
OUTPUT "No umbrella needed."
END IF
STOP
Question 6
Solution 6
Explanation:
Conditions allow the program to make decisions by evaluating whether a
statement is TRUE or FALSE. Based on the result, the program executes different
actions.
Example:
---
Question 7
Create a pseudocode that calculates the area of a triangle when the user inputs
the base and height.
Solution 7
Pseudocode:
START
base = INPUT "Enter the base of the triangle:"
height = INPUT "Enter the height of the triangle:"
area = 0.5 * base * height
OUTPUT area
STOP
---
Question 8
Solution 8
Python Code:
---
Would you like me to add more questions, target specific levels of difficulty, or
focus on a particular concept?
Here are exam questions and solutions inspired by the newly provided material
about flowcharts and conditional statements.
---
Question 9
Pseudocode:
START
password = "open123"
userInput = INPUT "Enter your password:"
IF password == userInput THEN
OUTPUT "Access Granted"
ELSE
OUTPUT "Access Denied"
ENDIF
STOP
---
Question 10
Solution 10
Flowchart Steps:
1. Start (Oval)
4. Stop (Oval)
Question 11
Explain the similarities and differences between the pseudocode and flowchart of
the login system.
Solution 11
Similarities:
Both have outputs for the true ("Access Granted") and false ("Access Denied")
cases.
Differences:
The pseudocode uses THEN, ELSE, and ENDIF, while the flowchart uses arrows for
True/False outcomes.
The pseudocode uses text for indentation, while the flowchart visually separates
actions into shapes.
---
Question Set 6: Conditional Logic Practice
Question 12
Solution 12
Pseudocode:
START
number = INPUT "Enter a number:"
IF number MOD 2 == 0 THEN
OUTPUT "The number is even."
ELSE
OUTPUT "The number is odd."
ENDIF
STOP
Question 13
What is the output if the user enters the number 15 in the pseudocode from
Question 12?
Solution 13
Calculation: 15 MOD 2 = 1
Question 15
Modify the pseudocode for the password program to allow up to three attempts
before displaying "Account Locked."
Solution 15
Pseudocode:
START
password = "open123"
attempts = 0
WHILE attempts < 3 DO
userInput = INPUT "Enter your password:"
IF password == userInput THEN
OUTPUT "Access Granted"
STOP
ELSE
OUTPUT "Incorrect password. Try again."
attempts = attempts + 1
ENDIF
ENDWHILE
OUTPUT "Account Locked"
STOP
---
Question 16
Convert the pseudocode in Question 15 into Python code.
Solution 16
password = "open123"
attempts = 0
if attempts == 3:
print("Account Locked")
Question 24
Write the pseudocode for a program that displays a heart on a micro:bit if the
light level is greater than 50.
Solution 24
Pseudocode:
START
lightLevel = display.read_light_level()
IF lightLevel > 50 THEN
OUTPUT heart
ENDIF
STOP
---
Question 25
Solution 25
lightLevel = display.read_light_level()
if lightLevel > 50:
display.show(Image.HEART)
---
Question 26
Explain the difference between the IF...THEN statement in pseudocode and the
equivalent if statement in MicroPython.
Solution 26
Pseudocode IF...THEN:
MicroPython if statement:
Requires a colon : at the end of the condition to indicate the start of the block.
Question 27
Design a test plan for the program that displays a heart if the light level is
greater than 50. Include expected outcomes for light levels of 10, 49, 50, 51, and
55.
Solution 27
---
Question 28
Write pseudocode for a program that displays a sad face if the light level is less
than 90.
Solution 28
Pseudocode:
START
lightLevel = display.read_light_level()
IF lightLevel < 90 THEN
OUTPUT sad face
ENDIF
STOP
Question 29
Solution 29
lightLevel = display.read_light_level()
if lightLevel < 90:
display.show(Image.SAD)
Question 32
Write the pseudocode for a program that displays a happy face on a micro:bit if
both the A and B buttons are pressed.
Solution 32
Pseudocode:
START
IF A button is pressed AND B button is pressed THEN
OUTPUT happy face
ENDIF
STOP
---
Question 33
Solution 33
---
Question 34
Write the pseudocode for a program that displays a happy face on the micro:bit if
either the A or B button (or both) is pressed.
Solution 34
Pseudocode:
START
IF A button is pressed OR B button is pressed THEN
OUTPUT happy face
ENDIF
STOP
Question 35
Solution 35
if button_a.is_pressed() or button_b.is_pressed():
display.show(Image.HAPPY)
---
Question 36
Write pseudocode for a program that displays a happy face on the micro:bit only
if the A button is not pressed.
Solution 36
Pseudocode:
START
IF A button is NOT pressed THEN
OUTPUT happy face
ENDIF
STOP
---
Question 37
Solution 37
if not button_a.is_pressed():
display.show(Image.HAPPY)
---
Question 38
Explain the difference between AND, OR, and NOT Boolean operators with
examples in pseudocode.
Solution 38
AND Operator: Both conditions must be true for the output to be executed.
Example:
OR Operator: At least one condition must be true for the output to be executed.
Example:
---
Question 39
Design a test plan for the program that uses the AND Boolean operator to display
a happy face only if both A and B buttons are pressed.
Solution 39
---
Question 40
Modify the program to display a sad face if neither A nor B button is pressed.
---
Here are exam questions and solutions related to using two micro:bits,
communication, and the radio function.
---
Question 41
Write pseudocode to send an image (e.g., a giraffe) from one micro:bit to another
when button A is pressed on the first micro:bit.
Solution 41
Pseudocode:
START
Set radio channel to 40
IF A button is pressed on micro:bit 1 THEN
Send "giraffe" message to micro:bit 2
ENDIF
IF A button is pressed on micro:bit 2 THEN
Send "giraffe" message to micro:bit 1
ENDIF
STOP
---
Question 42
Solution 42
radio.config(group=40)
radio.on()
while True:
if button_a.is_pressed():
radio.send('giraffe')
display.clear()
message = radio.receive()
if message:
display.show(Image.GIRAFFE)
---
Question 43
Solution 43
The radio library allows micro:bits to send and receive messages wirelessly.
---
Question 44
Solution 44
---
Question 45
Solution 45
radio.config(group=42)
radio.on()
while True:
message = radio.receive()
if message:
display.scroll(message)
if button_a.is_pressed():
display.clear()
radio.send("8, 5, 12, 12, 15")
---
Question 46
Predict what happens when the code in Question 45 is executed and explain the
expected outcomes.
Solution 46
It displays the sequence "8, 5, 12, 12, 15" as a scrolling message on its screen.
---
Question 47
Modify the code in Question 45 to send and display custom messages entered by
the user.
Solution 47
radio.config(group=42)
radio.on()
while True:
message = radio.receive()
if message:
display.scroll(message)
if button_a.is_pressed():
display.clear()
custom_message = "HELLO"
radio.send(custom_message)
---
Question 48
Solution 48
---
Would you like additional questions on this topic, or should I delve into advanced
use cases?
Here are exam questions and solutions based on the concepts of binary
communication and using strings with MicroPython and the micro:bit.
---
Question Set 12: Sending Strings and Binary Data Between Micro:bits
Question 49
What is machine code, and how does it relate to binary communication between
devices?
Solution 49
Machine Code:
---
Question 50
Write pseudocode to send the binary code for "hi" (01101000 for h and
01101001 for i) from one micro:bit to another.
Solution 50
Pseudocode:
START
Set radio channel to 40
Turn on radio
STOP
---
Question 51
Solution 51
radio.on()
radio.config(group=40)
while True:
if button_a.is_pressed():
radio.send('01101000') # Binary for 'h'
sleep(1000)
radio.send('01101001') # Binary for 'i'
message = radio.receive()
if message:
display.scroll(message)
---
Question 52
Design a test plan to verify the transmission of the binary codes for "hi."
Solution 52
---
Question 53
Explain how ASCII and binary are used to represent letters during communication
between micro:bits.
Solution 53
Maps each letter, digit, and symbol to a unique binary number (e.g., h =
01101000).
Binary:
During communication, micro:bits transmit binary sequences (1s and 0s) that
represent ASCII codes.
The receiving micro:bit can decode the binary message into characters using the
ASCII table.
---
Question 54
Modify the code from Question 51 to add a sound when each binary code is
received.
Solution 54
radio.on()
radio.config(group=40)
while True:
if button_a.is_pressed():
radio.send('01101000') # Binary for 'h'
sleep(1000)
radio.send('01101001') # Binary for 'i'
message = radio.receive()
if message:
display.scroll(message)
music.play(music.BA_DING)
---
Question 55
Solution 55
Letter Representation: h
Determination:
---
Question 56
How can the use of binary numbers improve communication efficiency between
micro:bits?
Solution 56
Efficiency Benefits:
Binary is compact and requires less memory and bandwidth than strings or
higher-level data formats.
---
Question 57
Solution 57
radio.send('<data>'):
Sends binary data or strings from one micro:bit to others in the same radio
group.
radio.receive():
---
Would you like more questions on binary encoding, ASCII communication, or
program implementation?
Here are exam questions and solutions based on sending hidden messages as
binary sequences and using sound with MicroPython and the micro:bit.
---
Question Set 13: Sending Hidden Messages Using Binary and Sound
Question 58
Write pseudocode for a program that sends a hidden word as a binary sequence
from one micro:bit to another.
Solution 58
Pseudocode:
START
Set radio channel to 40
Turn on radio
---
Question 59
Solution 59
radio.on()
radio.config(group=40)
while True:
if button_a.is_pressed():
radio.send('01101000') # Binary for 'h'
sleep(1000)
radio.send('01101001') # Binary for 'i'
sleep(1000)
radio.send('01100100') # Binary for 'd'
sleep(1000)
radio.send('01100101') # Binary for 'e'
sleep(1000)
radio.send('01101110') # Binary for 'n'
message = radio.receive()
if message:
display.scroll(message)
music.play(music.POWER_DOWN)
---
Question 60
Solution 60
For example:
h → 01101000
i → 01101001
d → 01100100
These binary numbers are sent as a sequence from one device to another.
The receiving device decodes the binary numbers back into characters using the
same ASCII table, reconstructing the hidden message.
---
Question 61
Modify the program in Question 59 to include a 1-second delay after each binary
sequence and add a visual indicator (e.g., LED blinking) to show the message is
being sent.
Solution 61
radio.on()
radio.config(group=40)
while True:
if button_a.is_pressed():
for char in ['01101000', '01101001', '01100100', '01100101', '01101110']:
display.show(Image.ARROW_E)
radio.send(char)
sleep(1000)
display.clear()
message = radio.receive()
if message:
display.scroll(message)
music.play(music.POWER_DOWN)
---
Question 62
Design a test plan to verify that a hidden word ("hidden") is sent correctly as
binary from one micro:bit to another.
Solution 62
---
Question 63
Solution 63
radio.send('<binary>'):
Sends the binary sequence from one micro:bit to all devices in the same radio
group.
radio.receive():
---
Question 64
Solution 64
After sending the final binary sequence, play a sound using music.play().
Example:
music.play(music.POWER_DOWN)
This provides auditory feedback to indicate that the entire message has been
sent.
---
Question 65
Modify the program to send your name as binary and display a smiley face when
the message is sent successfully.
Solution 65
radio.on()
radio.config(group=40)
while True:
if button_a.is_pressed():
for char in ['01101010', '01101111', '01101000', '01101110']: # Binary for
'john'
radio.send(char)
sleep(1000)
display.show(Image.HAPPY)
music.play(music.POWER_DOWN)
message = radio.receive()
if message:
display.scroll(message)
---