0% found this document useful (0 votes)
7 views

Computer Science 1

The document contains a series of questions and solutions related to pseudocode, flowcharts, conditional statements, and programming concepts using MicroPython and micro:bit. It includes pseudocode for various algorithms, flowchart conversions, and explanations of programming logic, along with Python code implementations. Additionally, it covers topics such as user input handling, mathematical operations, and communication between micro:bits using radio functions.

Uploaded by

kimmmmmmid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Computer Science 1

The document contains a series of questions and solutions related to pseudocode, flowcharts, conditional statements, and programming concepts using MicroPython and micro:bit. It includes pseudocode for various algorithms, flowchart conversions, and explanations of programming logic, along with Python code implementations. Additionally, it covers topics such as user input handling, mathematical operations, and communication between micro:bits using radio functions.

Uploaded by

kimmmmmmid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Question Set 1: Pseudocode and Flowcharts

Question 1

Write the pseudocode for an algorithm that calculates the perimeter of a


rectangle when the user inputs the length and width.

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

Convert the following pseudocode into a flowchart:

START
radius = INPUT "Enter the radius of the circle:"
area = 3.14 * radius * radius
OUTPUT area
STOP

Solution 2

Flowchart Steps:

1. Start (Oval shape)


2. Input radius (Parallelogram)
3. Calculate area = 3.14 * radius * radius (Rectangle)
4. Output area (Parallelogram)
5. Stop (Oval shape)

Question Set 2: Applying Mathematical Operations

Question 3

A company needs to calculate an employee's bonus, which is 15% of their


monthly salary. Write the pseudocode for this process.

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 Set 3: Conditional Statements

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

Explain the use of conditions in pseudocode. Provide one example.

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:

IF temperature > 30 THEN


OUTPUT "It's hot outside."
ELSE
OUTPUT "The weather is pleasant."
END IF

---

Question Set 4: Problem Solving

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

Write Python code to implement the pseudocode from Question 7.

Solution 8

Python Code:

base = float(input("Enter the base of the triangle: "))


height = float(input("Enter the height of the triangle: "))
area = 0.5 * base * height
print("The area of the triangle is:", area)

---

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 Set 5: Login System Using Conditional Statements

Question 9

A program requires a user to enter the correct password, stored as "open123", to


gain access.
Write the pseudocode for this program, ensuring it handles both correct and
incorrect inputs.
Solution 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

Convert the pseudocode from Question 9 into a flowchart.

Solution 10

Flowchart Steps:

1. Start (Oval)

2. Input userInput (Parallelogram)

3. Compare password and userInput using a decision box (Diamond):


If True, output "Access Granted" (Parallelogram).

If False, output "Access Denied" (Parallelogram).

4. Stop (Oval)

Question 11

Explain the similarities and differences between the pseudocode and flowchart of
the login system.

Solution 11

Similarities:

Both use the condition password == userInput.

Both have outputs for the true ("Access Granted") and false ("Access Denied")
cases.

Both execute the decision in sequence.

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

Write a program in pseudocode to determine if a number entered by the user is


even or odd. Include appropriate outputs.

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

Since the result is not 0, the output is:


"The number is odd."
---

Question Set 7: Password Security

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

while attempts < 3:


userInput = input("Enter your password: ")
if userInput == password:
print("Access Granted")
break
else:
print("Incorrect password. Try again.")
attempts += 1

if attempts == 3:
print("Account Locked")

Question Set 8: Light Level Conditions and MicroPython

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

Convert the pseudocode from Question 24 into MicroPython code.

Solution 25

from microbit import *

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:

Uses uppercase keywords IF and THEN.


Ends the condition block with ENDIF.

More abstract, focusing on logic rather than syntax.

MicroPython if statement:

Uses lowercase if.

Requires a colon : at the end of the condition to indicate the start of the block.

Uses indentation to define the block of code under the condition.

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 Set 9: Conditional Testing and Debugging

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

Convert the pseudocode from Question 28 into MicroPython code.

Solution 29

from microbit import *

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

Convert the pseudocode from Question 32 into MicroPython code.

Solution 33

from microbit import *

if button_a.is_pressed() and button_b.is_pressed():


display.show(Image.HAPPY)

---

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

Convert the pseudocode from Question 34 into MicroPython code.

Solution 35

from microbit import *

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

Convert the pseudocode from Question 36 into MicroPython code.

Solution 37

from microbit import *

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:

IF button_a is pressed AND button_b is pressed THEN


OUTPUT "Both buttons are pressed"
ENDIF

OR Operator: At least one condition must be true for the output to be executed.
Example:

IF button_a is pressed OR button_b is pressed THEN


OUTPUT "At least one button is pressed"
ENDIF

NOT Operator: The condition is true if the specified input is false.


Example:

IF NOT button_a is pressed THEN


OUTPUT "A button is not pressed"
ENDIF

---

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.

Solution 40 (MicroPython Code)

from microbit import *

if not button_a.is_pressed() and not button_b.is_pressed():


display.show(Image.SAD)

---

Would you like additional questions on Boolean operators, debugging, or test


planning?

Here are exam questions and solutions related to using two micro:bits,
communication, and the radio function.

---

Question Set 11: Micro:bit Communication and Radio Functions

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

Convert the pseudocode from Question 41 into MicroPython code.

Solution 42

from microbit import *


import radio

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

Explain how the radio library is used in MicroPython to enable communication


between micro:bits.

Solution 43
The radio library allows micro:bits to send and receive messages wirelessly.

Key steps include:

1. Configuration: Use radio.config(group=<number>) to set a communication


group (channel). All micro:bits in the same group can communicate.

2. Enable Radio: Use radio.on() to turn on the radio functionality.

3. Sending Messages: Use radio.send('<message>') to send a message.

4. Receiving Messages: Use radio.receive() to capture messages sent from other


micro:bits.

---

Question 44

Design a test plan to verify that pressing button A on micro:bit 1 displays a


giraffe on micro:bit 2 and vice versa.

Solution 44

---
Question 45

A program sends a sequence of numbers representing the letters "HELLO" (8, 5,


12, 12, 15) from one micro:bit to another. Write the MicroPython code for this
program.

Solution 45

from microbit import *


import radio

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

Scenario 1: When button A is pressed on the first micro:bit:


The sequence "8, 5, 12, 12, 15" is sent to the second micro:bit.

The display on the first micro:bit is cleared.

Scenario 2: When the second micro:bit receives the message:

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

from microbit import *


import radio

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

Explain how the radio.send() and radio.receive() functions work together in a


micro:bit network.

Solution 48

radio.send('<message>'): Sends a specified message from one micro:bit to all


other micro:bits in the same radio group.

radio.receive(): Listens for incoming messages. If a message is received, it is


stored as a string in a variable (or None if no message is received).

Together, these functions enable wireless communication by broadcasting and


capturing messages in real time.

---

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:

It is the lowest-level programming language understood by computers,


consisting of binary digits (0s and 1s).

Each binary number represents an instruction or data for the computer.

Relation to Binary Communication:

Binary communication transmits data as sequences of 1s and 0s between


devices. For example, ASCII codes represent characters as binary numbers for
communication.

---

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

IF button A is pressed THEN


Send '01101000' (binary for 'h') to the other micro:bit
Wait 1 second
Send '01101001' (binary for 'i') to the other micro:bit
ENDIF

IF message is received THEN


Display the received binary message
ENDIF

STOP

---

Question 51

Convert the pseudocode from Question 50 into MicroPython code.

Solution 51

from microbit import *


import radio

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

ASCII (American Standard Code for Information Interchange):

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

from microbit import *


import radio
import music

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

A binary number 01101000 is received by a micro:bit. Which letter does it


represent, and how is this determined?

Solution 55

Binary Number: 01101000

Letter Representation: h

Determination:

Use the ASCII table, which maps 01101000 to the letter h.

---

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.

It is universally understood by all digital devices.

Transmitting binary avoids unnecessary encoding and decoding overhead.

---

Question 57

Explain the role of radio.send() and radio.receive() in binary communication.

Solution 57

radio.send('<data>'):

Sends binary data or strings from one micro:bit to others in the same radio
group.

radio.receive():

Captures incoming messages from other micro:bits. If no message is received, it


returns None.

---
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

IF button A is pressed THEN


Send binary sequence for hidden word
ENDIF

IF message is received THEN


Display the binary sequence
Play a sound to indicate end of sequence
ENDIF
STOP

---

Question 59

Convert the pseudocode from Question 58 into MicroPython code.

Solution 59

from microbit import *


import radio
import music

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

Explain how binary sequences are used to represent hidden messages.

Solution 60

Each letter or character in a message is represented by a binary number using


the ASCII table.

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

from microbit import *


import radio
import music

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

Explain the role of radio.send() and radio.receive() in transmitting binary


messages between micro:bits.

Solution 63

radio.send('<binary>'):

Sends the binary sequence from one micro:bit to all devices in the same radio
group.

radio.receive():

Listens for incoming binary sequences. If a message is received, it is processed;


otherwise, it returns None.

---

Question 64

How can sound be used to indicate the end of a transmitted sequence in a


micro:bit program?

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

from microbit import *


import radio
import music

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)

---

You might also like