Student Name:
Teacher Name: Jahanara Taznina Orin
Unit-1(1)
Q. What is pseudocode?
Pseudocode is a tool that is used when designing programs. Pseudocode is made up of
two words: 'pseudo' and 'code'. Pseudocode means not real program statements.
Q. Write down the rules of writing pseudocode.
• No space. special character, not start with digits in variable
• Keywords are in upper/lower case but popular form: IF, INPUT, OUTPUT, etc
• Write only one statement per line.If a statement continues to the next line,
don’t number the continued lines. (good practice.)
• Use indentation (selection/iteration statement)
• Use END keywords followed by the condition: ENDIF/WHILE/CASE
• Statements are programming language independent.
• Write START at the beginning section and STOP at the end
• Use names from the problem, not coding terms.
• Comments begin with // and multi-line comments, each line starts with //.
Q. What is the assignment operator? given an example?
Values are assigned to an item or variable by using assignment operators is “”
“=” assignment should be made in the following format.
Example:
count 0
Sum Number1 + number2
Note: Some use assignment operators as “” and “=” but “” is valid
The variable on the left of the arrow () receives the value from the right side.
The expression on the right can be a single value or several values combined with
any of the following mathematical operators.
Q. What are data types? Explain with an example.
Data Type: A particular type of data item, as defined by the values it can take, the
programming language used, or the operations that can be performed on it.
Q. List all data type names used in pseudocode/programming code with an example?
Basic data types
The following keywords are used to designate basic data types:
• INTEGER: a whole number e.g. 5, –3
• REAL: a number capable of containing a fractional part e.g. 4.7, 0.3, –4.0, 0.0
• CHAR: a single character e.g. ꞌxꞌ, ꞌcꞌ, ꞌ@ꞌ
1
• STRING: a sequence of zero or more characters e.g. “This is a string”, “”
• BOOLEAN: the logical values TRUE and FALSE
Note: Literals are an example of a data type.
Description with the example of Python Data Type:
Q. What is a variable?
Variable: Name of memory used to store the data value.
Declaration:
variable= value;
a=10
Memory management of Python variables:
gu
Q. What is an identifier? explain with an example.
Q. Write down the rules of identifiers?
2
Q What is Constant? give an example con a constant?
• A constant is a value that remains unchanged throughout the execution of the program.
• Example: I = 3.14159
• Always try to write a variable in capital letters
Note: the value only needs to be changed once if circumstances change during the
initialization process. (Rare case)
Q. Write down the difference between a constant and a variable?
Q. Which two ways follow to write input and output statements in pseudocode? Explain
with an example?
Ans:
Key elements for input and output:
• Command/Message/prompt word with input/output
• Format: INPUT/OUTPUT <Message>, variable
Example:
INPUT “Enter values:”, x
OUTPUT “Result:”, x
• Variable with input/output
• Format: INPUT/OUTPUT variable
Example:
INPUT x
OUTPUT x
Q. Which signs are used to join more than one line in input and output statements?
• Example
OUTPUT “jshjah” & “kjkjk”, “jhjhj”
3
OUTPUT fullName ← firstName + " " + middleName + " " + lastName
Q. What is an arithmetic operation? write all symbols of arithmetic operators
and write pseudocode using arithmetic operators.
Ans: Arithmetic operators are symbols we use to perform mathematical calculations.
Example 1:
num 1
num2 2
result num + num2
OUTPUT (result)
Example 2
You can also write in the following way:
num1 2
num2 2
OUTPUT (num1 + num2)
Q. This algorithm will add together two numbers, store them in a variable,
and output the result.
ANS: follow Example 1 or 2
Q. Read the following algorithm and identify its purpose.
INPUT total
INPUT costl
total total + costl
INPUT cost2
total total + cost2
INPUT cost3
total total + cost3
OUTPUT "The total cost is ", total.
Now answer the following questions:
1 How many variables are in the algorithm?
Ans: 4 variables
2 What are the identifiers of the variables?
Ans: total, cost1, cost2, cost3
3 Which arithmetic operator is, or operators are, being used?
Ans: Addition operator: +
4 How many times is the assignment symbol used?
Ans: 3 times
5 What is the purpose of the comma (,) in the final statement?
4
Ans: To separate text and variable value in the output
6 Test the program with the following inputs, in the order given:
10 20 10 25
Write down the output.
Ans: The total cost is 65
Note: if asked to show steps, then follow the given answer:
Ans:
total = 10 cost1 = 20 cost2 = 10 cost3 = 25
• Step 1: total = 10
• Step 2: cost1 = 20
• total = total + cost1 → total = 10 + 20 = 30
• Step 3: cost2 = 10
• total = total + cost2 → total = 30 + 10 = 40
• Step 4: cost3 = 25
• total = total + cost3 → total = 40 + 25 = 65
Final Ans: The total cost is 65
Q Give a suitable pseudocode command word to output a message.
Ans: Any command such as OUTPUT, PRINT, WRITE
Q. Why is pseudocode called 'language independent"?
Ans: It does not use commands or syntax for one specific language, and it can be
understood by all programmers who can write high-level language programs.
Q. What are the two signs that can be used for assignment in pseudocode?
Ans: Equals (=) and back arrow (←)
Q What are the names of the variables in this pseudocode program?
first 1
second 2
third first + second
Ans: first, second, third
Q What is the value stored in answer after each pseudocode statement is run?
a answer ← 1 * 10
b answer ← (20/2) + 5
c answer 50*2 - 1
d answer 1+2-3
Ans: a. 10 b. 15 c. 99 d. 0
Q: What is pseudocode used for?
Q. Write down the characteristics of pseudocode
• To plan a program before writing real code.
• To focus on logic without worrying about syntax.
• It is language-independent and easy to understand.
• Helps programmers using different languages work together.
• Can be used instead of or with flowcharts.
5
• To design algorithms or programs.
Q. What are relational and logical operators? list all relational operators?
Ans: Relational and logical operators are used to compare values and make
decisions in programs. Relational and logical operators are used to compare values
and make decisions in programs.
Q. Write down pseudocode and a flowchart of the following programming
code?
num= int(input())
num2 = int (input())
answer = num + num2
print (answer)
pseudocode:
DECLARE num, num2: INTEGER
INPUT num
INPUT num2
answer ← num + num2
OUTPUT answer
Flowchart:
Q What is the difference between pseudocode and program code?
Pseudocode Program Code
6
Written in a specific programming
Written in plain English
language (like Python, Java, etc.)
No strict syntax rules Must follow strict syntax rules
Easy to understand and write Can be complex and harder to read
Cannot be executed by a computer Can be executed by a computer
Language-independent Language-dependent
Q. Which of the following is a valid/invalid example of pseudocode?
A. number INPUT
Ans: Valid
B. number = INPUT
Ans: Invalid
C. INPUT "Enter a number between 1 and 10", number
Ans: Valid
D. number = input ("Enter your name")
Ans: Invalid
Q. Which of these is not a valid example of pseudocode? if valid, true and if
false, explain why?
A. Output a message that tells the user to enter a word.
Ans: False, The first is not valid because the text to be output is not in
double quotation marks – it is an English statement and is not like code
B. OUTPUT "Enter a word"
Ans: True
C. writeToScreen ("Enter a word")
Ans: True
Q. What are the three main constructs in programming?
Ans: The three main constructs are:
• sequence
• selection
• iteration
Q. Take a look at this pseudocode algorithm.
1. valuel← 10
2. value2 ← value1 + 2
3. valuel← 100
4. valuel ← valuel - value2
5. value3 ← value1 * 2
6. value4 ← value3 / 4
Ans:
1. value1 10 100 88
2 value2 12
3 value3 176
4 value4 44
7
Ans:
Declaration Statement
Initialization
Assigning a value to a declared variable
The variable used for calculation/result/storage will be initialized most of the time.
Count 0, i 0, area 0 [store/result/calculation]
The input variable doesn’t need to be initialized
The user input variable will not initialize
Both declaration and initialization can be done: (avoid if not mentioned in question)
DECLARATION Count 0: INTEGER
Initialization declaration is optional in some cases, depending on the question.
8
Q. What is indentation? write down the usage of indentation?
1. Indent the inner code: neat and easy to read.
2. Show lines inside the IF block, and it will run if true.
3. Helps to understand the steps in the algorithm.
Q. What is a flowchart? Draw flowchart symbols with function and name?
Ans: A flowchart is a pictogram or graphical representation of program flow using different symbols.
Start/Stop
9
Make code:
Investigation:
Pseudocode Python code
10
Modified Code by changing value:
Prediction Output of modified code:
When running the modified code, the output is:
11