讲解COMP1002程序设计、辅导program编程语言、Python编程调试 解析Haskell程序|讲解数据库SQL

- 首页 >> Python编程
Computational Thinking and Problem Solving (COMP1002) and Problem Solving
Methodology in Information Technology (COMP1001)
Assignment THREE
(Due at noon on 30 October 2020)
1. [20 marks] Write a Python program that will prompt the user for his/her first name, last name and
a symbol. The program will print the first name, a space, and the last name on each line. But only
the first character is printed on the first line, the first two characters on the second line and so on
until the whole name is printed out. After that, the next line will print out the name except the last
character, the next next line the name except for the last two characters, and so on until the first
character is printed out. Also, for each odd-numbered column, the letter has to be replaced by the
input symbol. Note that the space should not be replaced. Your program should look like below:
2. [30 marks] In cryptography, a monoalphabetic substitution cipher is an encryption algorithm that
converts an English letter to another letter based on a key. For example, if the English text is
“dennis” and the key is “zaqxswcdevfrbgtnhymjukilop”, the encrypted text will be “xsggem”. The
following table shows the conversion:
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
z a q x s w c d e v f r b g t n h y m j u k i l o p
The first row is the original English letters and the second row is the encrypted letters. The key
must be a permutation of 26 letters. The highlighted letters above are the one used in above
example.
Write a Python program that accepts a key and a text string and produces the encrypted text in
lowercase letters. If the input key is not a permutation of 26 letters, the program should ask the
user to input again. Your program should look like below:
2
3. [25 marks] In the lecture, we have explained how we can add an arbitrary list of long integers
together using a few very simple procedures without doing even any mathematical computation.
The solution is expressed in pseudo-code. There are still some works to do when converting a
piece of pseudo-code to a program, e.g. data type conversion, precise loop variable setting, and
many small details to make a program. After this exercise, you could get a feeling on the
difference between designing in pseudo-code versus writing the program. Writing a program in C
will even be more difficult than in Python.
Write a Python program to realize the pseudo-code in the lecture note to add a list of long integers.
You need to set up a table for the first step to add two small numbers. You may use a list of lists,
or any appropriate data structure but the content must not be computed on-the-fly, following the
concept of symbolic computation. Your program should contain at least 4 functions implementing
the functions in the pseudo-code. Here are some sample outputs from your program:
4. [25 marks] (a) The following decision tree T classifies a post in a social network into four types:
technology, business, world, and unknown. Express the decision tree T in pseudo-code.
(b) Assuming that the probabilities of various branches of the tree are as shown, determine the
average number of if-statements to be executed when making classification.
(c) Redraw the decision tree in another “better” form T’ such that T and T’ are equivalent, i.e.
given any input case, the two decision trees will give the same output. Demonstrate that the two
trees are equivalent by giving at least an example in each type to support your candidate tree T’.
0.6 0.4
0.2 0.8 0.6 0.4
0.3 0.7
0.4 0.6 0.5 0.5
3
Submission Instructions
Follow the steps below:
1. Create a folder and name it as _,
e.g., 12345678d_CHANTaiMan
2. For Q1, Q2 and Q3. You need to submit the source file (.py). Name the .py files as
A3_Q__.py,
e.g., A3_Q1_12345678d_CHANTaiMan.py
3. For Q4. You need to type your answers in a word document and save it as a .pdf file. Name
the single .pdf file as A3__.pdf,
e.g., A3_12345678d_CHANTaiMan.pdf
4. Put all the .py and .pdf files into the folder.
5. Compress the folder (.zip, .7z, or .rar).
6. Submit the file to Blackboard.
A maximum of 3 attempts for submission are allowed. Only the last attempt will be graded. A late
penalty of 5% per hour will be imposed.

站长地图