SDD - Implementation Flashcards
In a programming language of your choice write code to create a create a variable called score and save 0 in the variable
score = 0
In a programming language of your choice write code to set name to Mr Oliver
name = “Mr Oliver
What type of programing construct is being demonstrated below:
Set valid to True
Write code to carry out this action in programming language of your choice
Construct: Assignment
Python: valid = True
Using a programing language of your choice write code to create a variable called totalCost and assign the value 17.80 it the variable
totalCost = 17.80
Write pseudocode to create a variable called favShow and assign Ninjago to it
favShow = “Ninjago” or
Set favShow to Ninjago
What do the arithmetic operation constructs shown below below do?
- /
+ Add
- Subtract
* Multiply
/ Divide
^ Exponent (power of)
What arithmetic operation constructs does this symbol ^ do?
^ Exponent (power of)
What is the result of the arithmetic operation constructs shown below :
**2^3 **
8
^ is exponent(power of)
2 3
2x2x2=8
Write the symbols for the arithmetic operation constructs shown below?
Add
Subtract
Multiply
Divide
Exponent
+ Add
- Subtract
* Multiply
/ Divide
^ Exponent (power of)
What type of programing construct is being demonstrated below:
add 5 to the total
arithmetic operation
A program has recorded the number of female and male students stored in variables called numFemale and numMale
Using a programming language of your choice: Calculated the total number of students and assign it to a variable called numStudents
numStudents = numFemale + numMale
Line 11 RECEIVE noTickets FROM (INTEGER) KEYBOARD
Line 12 set price to 25
Line 13 < calculate totalCost >
Using a programming language of your choice: Write the code for line 13
totalCost = noTickets x price
Code: totalPay = hoursWorked x rate + bonus
An employee has worked 10 hours, and has a rate of £12 per hour and a £30 pound bonus.
Caluate the totalPay
(12 x 10) + 30
120 + 30
150
What is Concatenation?
Concatenation means joining two or more strings together.
What is the name of the programing construct which joining two or more strings together.
Concatenation
A program stores the users name is a variable called name.
Using a programing language of your choice write code which would produce the following output if Lucy was stored in the variable name.
Output
Hello Lucy, how are you?
Python:
print(“Hello “ + name + “, how are you?”)
State the output after this program has been run.
Set subject to “Computer Science”
Set result to “pass”
Display “I can “ & result & “ “ & subject
I can pass Computer Science
Using a programming language of your choice write a program to do the following.
RECEIVE firstName FROM (STRING) KEYBOARD
RECEIVE surname FROM (STRING) KEYBOARD
SEND firstName & surname TO DISPLAY
Python:
firstName = input(“Enter First Name”)
surname = input(“Enter Surname”)
print(firstName + surname)
The total viewing figures for a show should be displayed as.
The show was watched by 1.2 million
Using a programming language of your choice and the variable numViewers
, write the code to produce the output above.
print(“The show was watched by” + numViewers + “million”)
What does the logical constructs < mean/do?
Less than
What does the logical constructs <= mean/do?
Less than or equal
What does the logical constructs >= mean/do?
Greater than or equal
What does the logical constructs != mean/do?
not equal
What does the logical constructs == mean/do?
equal to
What is the logical construct for less than?
<
What is the logical construct for less than or equal?
<=
What is the logical construct for greater than?
>
What is the logical construct for greater than or equals?
> =
What is the logical construct for not equal to?
!=
What is the logical construct for equal to?
==
What type of programing construct is demonstrated below?
if choice = “A”
Conditional statement/Selection statement
What is the condition the Pseudocode below?
IF choice == “A” THEN
DISPLAY “You have ordered Chips”
END IF
choice == “A”
What is the condition the Python below?
if exam_mark >= 70:
print(“Grade: A”)
exam_mark >= 70
How many conditions are shown in the Python below?
if exam_mark >= 70:
print(“Grade: A”)
elif exam_mark >= 60:
print(“Grade: B”)
elif exam_mark >= 50:
print(“Grade: C”)
3
exam_mark >= 70
elif exam_mark >= 60:
elif exam_mark >= 60:
A program should ask the user to enter their salary as an integer. If the salary is above 37,430 then a message should be displayed to say there salary above average
Using a design design techniques of your choice (pseudocode) write this program.
Get salary (integer) from user
If salary > 37430 then
Display “Salary above average”
End If
or
Get salary from user
If salary > 37430 then
________Send to screen “Your salary is above the national average”
Key points -
1) you must get the salary
2) you must have an If
3) it must have an the condition to check the salary is over 37430
4) you need to show scope of the if (end if or indented code)
___ used to show indent
A program should ask the user to enter the 1st phase of the software development process. If the user enters ‘Analysis’, the program should display the message “Correct”, otherwise it should display the message “Incorrect”.
Using a programming language of your choice write this program.
answer = input(“What is the 1st phase of the software development process?”)
if answer == “Analysis”:
print(“Correct”)
else:
__print(“Incorrect”)
___ used to show indent
The program shown below asks for a mark then works out the Grade the student should get.
1 Display ‘Enter Student Mark:’
2 Get Mark from User
3 if mark >= 70
4 __display ‘A’
5 if mark >= 60 and < 70
6 __display ‘B’
7 if mark >= 50 and < 60
8 __display ‘C’
9 if mark >= 40 and < 50
10 __display ‘D’
11if mark < 40
12 __display ‘Fail’
A programmer has noticed this code is not as efficient as it should be.
Why is the above code not efficient?
Using a programming language of your choice, rewrite line 3 - 12 to make the program more efficient.
1) The code uses multiple if statements when and elif statement should be used
2)
if mark >= 70:
__display ‘A’
elif mark >= 60:
__display ‘B’
elif mark >= 50:
__display ‘C’
elif mark >= 40:
__display ‘D’
else:
__display ‘Fail’
___ used to show indent
A program is required to rate hotels. The user should be asked to enter a rating between 0 and 10 and then the hotel recommendation will be shown.
Input: 8 or above Output: Excellent
Input: 5 to 7 Output: Reasonable
Input: Below 5 Output: Poor
Using a programming language of your choice, write a program for the above
rating = int(input(“Enter a rating:”))
if rating >= 8 :
__display ‘Excellent’
elif rating >= 5:
__display ‘Reasonable’
else:
__display ‘Poor’
___ used to show indent.
note: int required to make the code work but probably not required for the marking sheme
Name the 3 logical operators.
AND
OR
NOT
Describe what the AND logical operator does
AND
The condition will be True if both statements are True
Describe what the OR logical operator does
OR
The condition will be True if either one, or both of the statements are True
Describe what the NOT logical operator does
NOT
Reverses the result - A True result would become false
Which logical operator is described below?
The condition will be True if both statements are True
AND
The condition will be True if both statements are True
Which logical operator is described below?
The condition will be True if either one, or both of the statements are True
OR
The condition will be True if either one, or both of the statements are True
Which logical operator is described below?
Reverses the result
NOT
Reverses the result
State the output of this program when the status is valid.
IF NOT status = “expired” THEN
__display ‘Offer 1’
ELSE
__display ‘Offer2’
END IF
Offer1
Explanation:
status = expired would be false
Not status = expired /Not false would be True.
State the output of this program when the status is expired.
IF NOT status = “expired” THEN
__display ‘Offer 1’
ELSE
__display ‘Offer2’
END IF
Offer2
Explanation:
status = expired would be True
Not status = expired /Not True would be False.
State the output of this program when the status is expired.
IF status = “expired” OR status = “trial” THEN
__display ‘Offer 1’
ELSE
__display ‘Offer2’
END IF
Offer1
Explanation:
status = expired would be TRUE
status = trial would be FALSE
OR only needs for one condition to be met
State the output of this program when the status is Renewed.
IF status = “expired” OR status = “trial” THEN
__display ‘Offer 1’
ELSE
__display ‘Offer2’
END IF
Offer2
Explanation:
status = expired would be FALSE
status = trial would be FALSE
Both statements evaluate to FALSE
OR - at least one condition must be met
State the output of this program when the status is valid and the age 22
IF status = “expired” OR age<16
THEN
__display ‘Offer 1’
ELSE
__display ‘Offer2’
END IF
Offer2
Explanation:
status = expired would be FALSE
age<16 would be FALSE
Both statements evaluate to FALSE
OR - at least one condition must be met
State the output of this program when the status is expired and the age 14
IF status = “expired” OR age<16
THEN
__display ‘Offer 1’
ELSE
__display ‘Offer2’
END IF
Offer1
Explanation:
status = expired would be TRUE
age<16 would be TRUE
Both statements evaluate to TRUE
OR - at least one condition must be met (both being TRUE would met this requirement)
State the output of this program when the status is expired and the age 14
IF status = “expired” AND age<16
THEN
__display ‘Offer 1’
ELSE
__display ‘Offer2’
END IF
Offer1
Explanation:
status = expired would be TRUE
age<16 would be TRUE
Both statements evaluate to TRUE
AND - Both conditions must be true which they are in this case.
State the output of this program when the status is expired and the age 22
IF status = “expired” AND age<16
THEN
__display ‘Offer 1’
ELSE
__display ‘Offer2’
END IF
Offer2
Explanation:
status = expired would be TRUE
age<16 would be False
Only one statements evaluates to TRUE
AND - both conditions must be met, in this case they have not been
A progrm is required for a shop to calculate the total bill to be charged to a customer. A 10% discount should be applied to any business customer who spends more than £1,000.
Algorithm
1. Get cost of Goods
2. Get accountType
3. Calculate Discount to be applied
4. Calculate total cost
Refine step 3. Using a programming language of your choice, write a program for the above.
IF type == “business” AND goodsCost > 1000:
__discount = goodsCost * 0.1
ELSE:
__discount = 0
or
discount = 0
IF type == “business” AND goodsCost > 1000:
__discount = goodsCost * 0.1
___ used to show indent.
n.b. variable name not given in question therefore any sensible variable name can be used.
Name the 2 type of loops
Fixed Loop and Conditional Loop
Describe a Fixed Loop
A fixed loop will always execute a set(fixed) number of times.
Note when you start running the loop you will know how many times it will run.
Describe a Conditional Loop
conditional loop will execute while a specific condition is being met, or until a specific condition is met.
What type of loop is this
Pseudocode
REPEAT WHILE number < 1
DISPLAY “Error, please enter number again”
END REPEAT
Conditional Loop
What type of loop is this
Pseudocode
REPEAT WITH counter FROM 1 to 10
DISPLAY counter
END REPEAT
Fixed Loop
What Type of Loop is this?
for counter in range(0, 10):
__print(counter)
fixed loop
What type of loop is this?
guess = input(“Enter Guess”)
while guess != “bob”:
__print(“You are wrong guess again”)
__guess = input(“Enter Guess”)
conditional
name the 3 predefined functions you need to know for Nat 5
random
round
length
What does the random function do?
The random function returns a random number between two parameters.
what does the round predefined function do?
The round function returns a decimal number rounded to a given number of places.
what does the length predefined function do?
The length function returns the length of a string
Using a programming language of your choice create a program to pick a number between 1 and 50 and assign it to a variable called pick.
import random
pick= random.randint(1, 50)
Using a programming language of your choice, write a code to round the totalPrice to 2 decimal places and assign the value a variable called displayPrice
displayPrice = round(totalPrice,2)
Using a programming language of your choice, write code to check a the length of a variable called password and save the result in a new variable called passwordLen
passwordLen = len(password)
Name the 3 standard algorithms for National 5
running total
input validation
traversing an array
Write the steps for the input validation standard algorithm
The steps of this algorithm are:
1. Ask the user to input something
2. Start a while loop, while the input does not meet the condition (e.g. while age < 15)
3. Show an error message
4. Ask the user to input (again)
5. End while loop
Write the steps for the running total within a loop standard algorithm
Potenial Step: Set up the values in the array (this may not be required - as array may already be created or updated via user input)
1. Set total to 0
2. Start a for loop (for or while)
3. Add value from array/user input to total
4. End for loop
5. (possible step) You me be required to display to display the total at the end of the loop
Write the steps for the traversing a 1-D array standard algorithm
- Start a for loop, for the number of elements in the array
- Use the array element[counter] to perform action on array element (e.g print)
- End the for loop