0% found this document useful (0 votes)
0 views6 pages

Programming Techniques Worksheet 2 Selection

Uploaded by

19arahman
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)
0 views6 pages

Programming Techniques Worksheet 2 Selection

Uploaded by

19arahman
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/ 6

Worksheet 2 Selection

Unit 11 Programming techniques

Worksheet 2 Selection
Task 1

1. Evaluate the following conditions to TRUE or FALSE

True or
Grade1 Grade2 Condition
false?
80 67 (Grade1>=80) AND (Grade2 >=80) false
82 80 (Grade1>=80) OR (Grade2>=80) true
35 50 (Grade1>30) OR (Grade1<50) true
65 1 (Grade1<30) OR (Grade1 >80) false
0 75 NOT(Grade1>50) AND (Grade2>50) true
65 85 NOT(Grade1<80) AND NOT (Grade2<80) false

2. Write a pseudocode algorithm to include a validation Rule: Read a pupil age and output a
message “Valid pupil age” if it is at least 10 and less than 19 years old. Otherwise output
the message “Invalid input: enter a value from 11 to 18”.

Age= int(input(“enter age of pupil: 2))


if Age >= 10 AND <19 then
print(“valid age”)
else
print(“invalid age, enter an age from 11-18”)

1
Worksheet 2 Selection
Unit 11 Programming techniques

Task 2

3. An online bookstore gives free 2nd class mail delivery (code 2) for any order value greater
than or equal to £15.00
For order values less than £15.00, 2nd class mail delivery costs £3.50.
For any value of order, a customer may choose to pay £5.00 for guaranteed next day
delivery (code 1).
(a) Write pseudocode for an algorithm which allows the user to enter the total value of their
order. They are then asked whether they want to pay for guaranteed next day delivery.
Depending on their answer, and the value of the order, the program displays the
postage charge and the overall total charge.

orderValue = float(input("Enter the total value of your order: "))

nextDayDelivery = input("Do you want guaranteed next day delivery? (Yes/No): ")

if nextDayDelivery == "Yes":

postageCharge = 5.00 # Next day delivery charge

else:

if orderValue >= 15.00:

postageCharge = 0.00 # Free 2nd class delivery for orders >= £15.00

else:

postageCharge = 3.50 # 2nd class delivery charge for orders < £15.00

totalCharge = orderValue + postageCharge

print(f"Postage charge: £{postageCharge:.2f}")

print(f"Total charge: £{totalCharge:.2f}")

END

(b)

(b) What will be the postage cost in each of the following cases?

(i) Order value £10.00 Postage code 2:

(ii) Order value £15.00 Postage code 2:

(iii) Order value £30.00 Postage code 1:

4. Study the decision table below and develop a solution using pseudocode that meets the
rules described in the table and outputs a message describing the action to be taken.

Rules

2
Worksheet 2 Selection
Unit 11 Programming techniques
Exam >90 Y Y
Exam >80 and <=90 Y Y
Condition
Exam >70 and <=80 Y Y
s
Exam <=70 Y Y
Attendance > 90% Y Y Y Y N N N N
Grade = A X
Actions Grade = B X
Grade = C X
Fail X X X X X

3
Worksheet 2 Selection
Unit 11 Programming techniques

Task 3

5. A home security system is designed to sound an alarm if a movement sensor on the ground
or first floor signals movement when the alarm is triggered. The trigger is set to ON when
the family go out and set to OFF via a keypad when they return home. If the alarm is
triggered and a movement is detected by one of the movement sensors, the alarm is set to
ON which will cause a siren to wail and light to flash. A message is sent via text to the
owner’s mobile phone indicating an intrusion was detected. You are required to write an
algorithm to read the input from the sensors and the alarm trigger switch and produce
appropriate output by setting the Alarm to ON and sending and “Intruder alert” message to
the phone.

(a) Write this in pseudocode using a nested IF statement. Use two variables
movementGround and movementFirst. When sending the alert differentiate the
message to tell the user if the intrusion is on the ground or first floor. Send two
messages if intruders are detected on both floors.
movementGround = bool(input("Movement detected on ground floor (True/False): "))
movementFirst = bool(input("Movement detected on first floor (True/False): "))
alarmTrigger = bool(input("Is the alarm ON? (True/False): "))

if alarmTrigger:
if movementGround:
alarmStatus = "ON"
print("Intruder alert: Ground floor intrusion detected!")

if movementFirst:
alarmStatus = "ON"
print("Intruder alert: First floor intrusion detected!")

if movementGround and movementFirst:


print("Intruder alert: Ground floor and First floor intrusion detected!")

(b) Write a similar algorithm to the first. Use the same sensor variables but this time use
Boolean operators to write the algorithm using a single IF.. THEN.. ELSE statement to
test for movement on either floor if the alarm has been triggered. You do not need to
differentiate the message, simply output “Intruder alert!” if the trigger is ON and
movement is detected.
movementGround = bool(input("Movement detected on ground floor (True/False): "))
movementFirst = bool(input("Movement detected on first floor (True/False): "))
alarmTrigger = bool(input("Is the alarm ON? (True/False): "))

# Check if alarm is ON and if movement is detected on either floor

4
Worksheet 2 Selection
Unit 11 Programming techniques
if alarmTrigger and (movementGround or movementFirst):
print("Intruder alert!")
else:
print("No intruder detected.")

6. Write a program in pseudocode that displays a menu with three option choices for a car
rental firm. The choices are
1: Economy Car
2: Saloon Car
3: Sports Car

After the user enters a choice, the program will tell them if it was invalid, in which case the
program will end.
If a valid choice is entered, the program will ask them if they wish to proceed or cancel.
After they respond, the program will confirm their response and then output the message
“Have a nice day.”

5
Worksheet 2 Selection
Unit 11 Programming techniques

7. Write [part of] a pseudocode program that allows the user to input medical symptoms, and
gives a diagnosis.
For example: The program may ask if the patient has a temperature. If they answer Yes,
they are asked if their throat is sore. If the throat is sore, then print “You may have a throat
infection”. If the throat is not sore, ask if they have a cough, and if they answer Yes, then
print “You have a chest infection”. If neither, they are diagnosed with a fever.
If they do not have a temperature, you can end the program with a suitable message.

temperature = input("Do you have a temperature? (Yes/No): ")

if temperature == "Yes":
sore_throat = input("Do you have a sore throat? (Yes/No): ")

if sore_throat == "Yes":
print("You may have a throat infection.")
else:
cough = input("Do you have a cough? (Yes/No): ")

if cough == "Yes":
print("You have a chest infection.")
else:
print("You have a fever.")
else:
print("No temperature detected. You may not have an infection.")

You might also like