XMSS 2018 P2
XMSS 2018 P2
You are tasked to evaluate the loan packages from four banks in Singapore. All the
loans are using compound interest. You are required to finish setting up the
spreadsheet to show the total amount payable to each bank at the end of the loan
period.
Open the file LOAN. You will see the following data.
1 Use a formula to convert the number of years in the Loan Tenure (year) column
to number of months and use it to complete the Loan Tenure (month) column.
The values should be displayed as number with no decimal places. [3]
2 Use an appropriate function to search for the Interest Rate per Month (x year
loan) in the Rates table and use it to complete the Loan Interest Rate column.
The interest rate should be displayed as percentage of two decimal places. [4]
3 Use an appropriate function to calculate the total amount of payable to the bank
at the end of the loan and use it to complete the Total Amount Payable to
Bank column. These values should be displayed as currency of two decimal
places. [3]
Save and close your file.
3
Task 2
The following program accepts three words and joined them together to form a
sentence by adding a space in between them, and eventually prints out the entire
sentence.
num_of_words = 3
result = ""
for count in range(num_of_words):
word = input("Enter a word: ")
result += word
if count < num_of_words-1:
result += " "
print("Sentence =", result)
(b) Prints out the total number of characters used to construct the entire
sentence [1]
(c) Prints out the words entered on separate lines before the sentence is
printed, e.g.
Word List:
I
love
Computing
Sentence = I love Computing [5]
(d) Checks if the word input has a length of 1 to 15 characters, and if not, asks
the user for the input again as necessary. [3]
Task 3
The following program should read a denary non-negative integer from the user. The
program will then convert the denary integer to its binary value and print it to the
screen. The “division by 2” method is employed to carry out the conversion.
There are several syntax errors and logical errors in the program.
NEW_BASE == 3
num = Input("Enter a non-negative integer: "
num = float(num)
result = ""
q = num
r = q % NEW_BASE
result = str(r) + result
q = q // NEW_BASE
while q > 0
r = q % NEW_BASE
result = result + str(r)
q = q / NEW_BASE
print(result, "in Decimal is", num, "in Binary.")
5 Identify and correct the errors in the program so that it works correctly according
to the description above. [10]
Task 4
You have been asked to write a program to simulate the Caesar Cipher. The cipher
was used by Julius Caesar (Roman dictator) to encrypt written instructions to his
generals.
The Caesar Cipher is a type of substitution cipher where each letter in the original
plaintext message is replaced by a letter some fixed positions down the alphabet.
Consider the case where each letter in the plaintext is shifted by 3 places. As a
result, A becomes D, B becomes E, C becomes F, D becomes G, etc. The last three
letters in the alphabet are wrapped around to the beginning: X becomes A, Y
becomes B and Z becomes C. Non-letter characters are not modified by the cipher.
5
Table 4 shows an example where the letters have been shifted to the right by 3.
Note that the letters “wrap-around” at the end.
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
Table 4
The plaintext of “HELLO” will be encrypted as “KHOOR” based on the cipher that
has the positions of the alphabet shifted to the right by 3.
7 When your program is working, use the following plaintexts and shift values as
test data to show your test results:
End of paper