0% found this document useful (0 votes)
23 views7 pages

Constructs of A Pseudocode - Decision or Selection Classroom Excersises

Uploaded by

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

Constructs of A Pseudocode - Decision or Selection Classroom Excersises

Uploaded by

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

ALGORITHMIC THINKING WITH PYTHON

MODULE 2
Constructs of a pseudocode - Decision or Selection

Class Room Exercises


1. Problem Statement: Write a pseudocode that checks if a number is greater than 100. If it is,
print "Number is greater than 100."

BEGIN
PRINT "Enter a number:"
INPUT number
IF number > 100 THEN
PRINT "Number is greater than 100."
END IF
END

2. Problem Statement: Write a pseudocode to check if a person is eligible for a driving license.
The minimum age requirement is 16 years. If the person is 16 or older, print "Eligible for a
driving license." Otherwise, print "Not eligible for a driving license."
BEGIN
PRINT "Enter your age:"
INPUT age
IF age >= 16 THEN
PRINT "Eligible for a driving license."
ELSE
PRINT "Not eligible for a driving license."
END IF
END

3. Problem Statement: Write a pseudocode that assigns a grade based on the marks obtained
by a student:
• If the marks are 90 or above, the grade is "A."
• Otherwise, print "Below A grade."

BEGIN
PRINT "Enter your marks:"
INPUT marks
IF marks >= 90 THEN
PRINT "Grade: A"
ELSE
PRINT "Below A grade."
END IF
END

Prof. Sarju S, Dept. of CSE, SJCET Palai Page 1 of 7


ALGORITHMIC THINKING WITH PYTHON

4. Problem Statement: Write a pseudocode to check whether a number is divisible by 5. If it is,


print "Divisible by 5." Otherwise, print "Not divisible by 5."

BEGIN
PRINT "Enter a number:"
INPUT number
IF number MOD 5 = 0 THEN
PRINT "Divisible by 5."
ELSE
PRINT "Not divisible by 5."
END IF
END
5. Problem Statement: Write a pseudocode that checks if a student has passed or failed an
exam. The passing mark is 40 or above. If the student scores 40 or more, print "Pass."
Otherwise, print "Fail."

BEGIN
PRINT "Enter your exam score:"
INPUT score
IF score >= 40 THEN
PRINT "Pass"
ELSE
PRINT "Fail"
END IF
END

6. Problem Statement: Write a pseudocode that checks whether a number is even or odd using
a simple if construct.
BEGIN
PRINT "Enter a number:"
INPUT number

IF number MOD 2 = 0 THEN


PRINT "The number is even."
END IF
END

7. Problem Statement: Write a pseudocode to check if a person is eligible to vote. To be


eligible, the person must be 18 years or older.
BEGIN
PRINT "Enter your age:"
INPUT age

IF age >= 18 THEN


PRINT "You are eligible to vote."
ELSE
PRINT "You are not eligible to vote."
END IF
END

Prof. Sarju S, Dept. of CSE, SJCET Palai Page 2 of 7


ALGORITHMIC THINKING WITH PYTHON

8. Problem Statement: A customer visits an online store that offers a discount based on the
total purchase amount:
• If the total is greater than $500, apply a 20% discount.
• If the total is between $200 and $500 (inclusive), apply a 10% discount.
• If the total is less than $200, no discount is applied.
Write a pseudocode that calculates the final amount after applying the discount.

BEGIN
PRINT "Enter the total purchase amount:"
INPUT total_amount

IF total_amount > 500 THEN


discount = total_amount * 0.20
final_amount = total_amount - discount
PRINT "20% discount applied. Final amount is:",
final_amount
ELSE IF total_amount >= 200 AND total_amount <= 500 THEN
discount = total_amount * 0.10
final_amount = total_amount - discount
PRINT "10% discount applied. Final amount is:",
final_amount
ELSE
PRINT "No discount applied. Final amount is:",
total_amount
END IF
END

9. Problem Statement: Create a pseudocode for a simple traffic light system. The system
operates in the following way:
• If the light is green, cars can go.
• If the light is yellow, cars should slow down.
• If the light is red, cars must stop.
Write the pseudocode that determines what message to display based on the light color
input.

BEGIN
PRINT "Enter the traffic light color (green, yellow, red):"
INPUT light_color

IF light_color = "green" THEN


PRINT "Go!"
ELSE IF light_color = "yellow" THEN
PRINT "Slow down!"
ELSE IF light_color = "red" THEN
PRINT "Stop!"
ELSE
PRINT "Invalid color!"
END IF
END

Prof. Sarju S, Dept. of CSE, SJCET Palai Page 3 of 7


ALGORITHMIC THINKING WITH PYTHON

10. Problem Statement: Write a pseudocode that checks the strength of a user’s password. The
rules for checking the strength are:
• If the password length is less than 6 characters, it is considered "Weak."
• If the password contains at least 6 characters but less than 10 characters, it is
"Moderate."
• If the password contains 10 or more characters, it is "Strong."

BEGIN
PRINT "Enter your password:"
INPUT password

password_length = LENGTH(password)

IF password_length < 6 THEN


PRINT "Password strength: Weak"
ELSE IF password_length >= 6 AND password_length < 10 THEN
PRINT "Password strength: Moderate"
ELSE IF password_length >= 10 THEN
PRINT "Password strength: Strong"
END IF
END
11. Write a pseudocode program that takes a day of the week as input (e.g., "Monday", "Tuesday")
and prints a specific message for that day using a case structure. For example, if the input is
"Monday", the output could be "It's the start of the week." If the input is invalid (not a day of
the week), display an appropriate error message.
START
Declare dayOfWeek as String
Input dayOfWeek

CASEOF (dayOfWeek)
CASE "Monday":
PRINT "It's the start of the week."
BREAK
CASE "Tuesday":
PRINT "It's the second day of the week."
BREAK
CASE "Wednesday":
PRINT "Mid-week!"
BREAK
CASE "Thursday":
PRINT "Almost the weekend."
BREAK
CASE "Friday":
PRINT "Weekend is near!"
BREAK
CASE "Saturday", "Sunday":
PRINT "It's the weekend!"
BREAK
DEFAULT:
PRINT "Invalid day entered."
END CASE

Prof. Sarju S, Dept. of CSE, SJCET Palai Page 4 of 7


ALGORITHMIC THINKING WITH PYTHON

END
12. Create a pseudocode program that accepts a numerical score (0-100) as input and assigns a
letter grade (A, B, C, D, F) based on that score using a case structure. For example, if the score
is between 90 and 100, the grade should be "A". Ensure the program handles scores outside
the 0-100 range by displaying an error message.

START
Declare score as Integer
Input score

CASEOF (score)
CASE score >= 90 AND score <= 100:
PRINT "Grade A"
BREAK
CASE score >= 80 AND score < 90:
PRINT "Grade B"
BREAK
CASE score >= 70 AND score < 80:
PRINT "Grade C"
BREAK
CASE score >= 60 AND score < 70:
PRINT "Grade D"
BREAK
CASE score < 60:
PRINT "Grade F"
BREAK
DEFAULT:
PRINT "Invalid score entered."
END CASE
END

13. Write a pseudocode program that functions as a simple calculator. The program should take
two numbers and an operator (+, -, *, /) as input and use a case structure to perform the
corresponding mathematical operation. If the user inputs a division by zero, the program
should display an error message instead of attempting the calculation. After the operation, the
program should print the result.

START
Declare number1, number2 as Float
Declare operator as Character
Input number1
Input number2
Input operator

CASEOF (operator)
CASE '+':
result = number1 + number2
PRINT "Result: " + result
BREAK
CASE '-':
result = number1 - number2
PRINT "Result: " + result

Prof. Sarju S, Dept. of CSE, SJCET Palai Page 5 of 7


ALGORITHMIC THINKING WITH PYTHON

BREAK
CASE '*':
result = number1 * number2
PRINT "Result: " + result
BREAK
CASE '/':
IF number2 != 0:
result = number1 / number2
PRINT "Result: " + result
ELSE:
PRINT "Cannot divide by zero"
BREAK
DEFAULT:
PRINT "Invalid operator"
END CASE
END

14. Develop a pseudocode program that simulates a traffic light control system using a case
structure. The program should take a color input (Red, Yellow, or Green) and print the
corresponding action ("Stop", "Prepare to stop", or "Go"). If the input color is not valid, display
an error message.
START
Declare lightColor as String
Input lightColor

CASEOF (lightColor)
CASE "Red":
PRINT "Stop"
BREAK
CASE "Yellow":
PRINT "Prepare to stop"
BREAK
CASE "Green":
PRINT "Go"
BREAK
DEFAULT:
PRINT "Invalid light color"
END CASE
END

15. Create a pseudocode program that takes the number of a month (1 for January, 2 for February,
etc.) as input and uses a case structure to print how many days are in that month. For
simplicity, assume February always has 28 days. Group the months with the same number of
days into one case in the case structure where possible. If an invalid month number is input
(e.g., 13), display an error message

START
Declare month as Integer
Input month

CASEOF (month)
CASE 1, 3, 5, 7, 8, 10, 12:
PRINT "31 days"

Prof. Sarju S, Dept. of CSE, SJCET Palai Page 6 of 7


ALGORITHMIC THINKING WITH PYTHON

BREAK
CASE 4, 6, 9, 11:
PRINT "30 days"
BREAK
CASE 2:
PRINT "28 days"
BREAK
DEFAULT:
PRINT "Invalid month entered."
END CASE
END

16. Write a pseudocode program that evaluates a student's performance based on their letter
grade (A, B, C, D, F) using a case structure. The program should take the grade as input and
print a corresponding performance message, such as "Excellent" for an "A" or "Fail" for an "F".
Ensure the program can handle invalid grades by displaying an error message.

START
Declare grade as Character
Input grade

CASEOF (grade)
CASE 'A':
PRINT "Excellent"
BREAK
CASE 'B':
PRINT "Good"
BREAK
CASE 'C':
PRINT "Average"
BREAK
CASE 'D':
PRINT "Poor"
BREAK
CASE 'F':
PRINT "Fail"
BREAK
DEFAULT:
PRINT "Invalid grade"
END CASE
END

Prof. Sarju S, Dept. of CSE, SJCET Palai Page 7 of 7

You might also like