0% found this document useful (0 votes)
24 views4 pages

XMSS 2018 P2

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)
24 views4 pages

XMSS 2018 P2

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/ 4

2

XINMIN SS PRELIM 2018


Task 1

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.

Save the file as EVA_<Your name>_<Class>_<Index number>

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)

Open the file JOINWORDS.py

Save the file as MYWORDS_<Your name>_<Class>_<Index number>

4 Edit the program so that it:

(a) Accepts only 5 words [1]

(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]

Save your program.


4

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.")

Open the file D2B.py

Save the file as MYD2B_<Your name>_<Class>_<Index number>

5 Identify and correct the errors in the program so that it works correctly according
to the description above. [10]

Save your program.

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.

The program should allow you:

• To enter a plaintext in uppercase.


• To enter the shift value for the cipher.
• To encrypt the plaintext.
• Not to encrypt non-letter characters.
• To display the encrypted message on the screen. Your output must look like
this:

Please enter your plaintext: HELLO WORLD!


Please enter a shift value: 3
Encrypted message: KHOOR ZRUOG!

6 Write your program and test that it works. [12]

Save your program as CIPHER1_<Your name>_<Class>_<Index number>

7 When your program is working, use the following plaintexts and shift values as
test data to show your test results:

Plaintext Shift value


HELLO WORLD! 3
XINMIN SEC 2
PHYSICS RULES 1

Take a screen shot of your results and save it as a bitmap


CIPHERRESULTS_<Your name>_<Class>_<Index number> [5]

8 Save your program as CIPHER2_<Your name>_<Class>_<Index number>


Extend your program to only allow shift values of 1 to 25 to be entered, and if
not, ask the user for the input again as necessary. [3]

Save your program.

End of paper

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy