CSIT110/CSIT810

Assignment 2 (10%)

Objectives

– Able to write clear code with comments and follow coding convention

– Able to use variables with meaningful names and correct data types

– Able to define functions and class objects

Question 1. Write a function that satisfies the following specifications.

Function name question_1

Detailed information Write a program to take in the following input.

You may use any text for the prompt

Get 3 inputs from the user.

Treat the first 2 inputs as str objects

Treat the last input as an int object

Let N be the number given in the last user input.

Display a string with the following content – a string containing N number

of the first string object, and each of them are separated by the second

string object.

Do not use string concatenation or f-string.

Use the end parameter in the print function to display the string object.

There should be a newline at the end of the string.

You may assume the input are valid.

Example console

output

prompt1 hava

prompt2 na

prompt3 4

havanahavanahavanahava

Question 2. Write a function that satisfies the following specifications.

Function question_2

Parameters –

Return Value –

Detail Information Get user inputs for an upper bound number and a gap number with the

prompts shown in the example.

The upper bound number is a non-negative integer and the gap is a positive

integer.

The program displays numbers from 0 to the upper bound, and from upper

bound down to 0. The gap between two consecutive numbers must be

correct according to the user input. Your program must work exactly like

the following example (the text in bold indicates the user input)

Your program does not have to handle error cases when

● upper bound < 0.

● gap <= 0

You should test your program for different kind of scenarios, here

are some examples for testing:

○ Upper bound = 5, gap = 1: results 0, 1, 2, 3, 4, 5. sum=15, and 5,

4, 3, 2, 1, 0. sum=15.

○ Upper bound = 5, gap = 2: results 0, 2, 4. sum=6 and 5, 3, 1.

sum=9.

○ Upper bound = 5, gap = 7: results 0. sum=0 and 5. sum=5.

○ Upper bound = 15, gap = 7: results 0, 7, 14. sum=21 and 15, 8,

1. sum=24.

○ Upper bound = 0, gap = 1: results 0. sum=0 and 0. sum=0.

There is a space after every colon.

Example console

output

Enter upper bound: 20

Enter gap: 3

Go forward: 0, 3, 6, 9, 12, 15, 18.

Sum of numbers = 63

Go backward: 20, 17, 14, 11, 8, 5, 2.

Sum of numbers = 77

Question 3. Write a function that satisfies the following specifications.

Function question_3

Parameters –

Return Value –

Detail Information This function computes the total interest earned for a given year based on

the following rated.

Base Interest:

Ordinary Account (OA): 2.5% per annum.

Special Account (SA): 4% per annum.

Medisave Account(MA): 4% per annum.

Retirement Account(RA): 4% per annum (only applicable for those age 55

and above.)

Extra Interest:

Age Extra interest (capped at $20,000 for

OA)*

Below 55 years old 1% per annum on the first $60,000

55 years old and above 2% per annum on the first $30,000, 1% per

annum on the next $30,000

* OA contributes a maximum of $20000 to the extra interest calculation.

Using the prompts shown in the example, calculate and display the interest

earned for in one year assuming no money was deposited into the account

during that period.

You do not have to round the interest up or down.

You should test your program for different kind of scenarios, here is

another example for testing:

35, 30000, 10000, 20000 -> $2450.00

Example 1 console

output

Enter current age: 35

Enter current amount in OA: 10000

Enter current amount in SA: 10000

Enter current amount in MA: 10000

Your interest rate this year will be $1350.00

Example 2 console

output

Enter current age: 65

Enter current amount in OA: 10000

Enter current amount in SA: 10000

Enter current amount in MA: 10000

Enter current amount in RA: 10000

Your interest rate this year will be $2150.00

Question4. Write a function that satisfies the following specifications.

Function Name question_5

Detailed

Information Tim downloaded a large number of poorly named files, e.g.

“patient_zero[20150203].txt”, “[shn]shn_batch101.csv”,

“[x264]psa_recording[1280×720].mp4”

and would like to automatically clean up these filenames by removing

all instances of square brackets and the contents contained within.

1. Prompts for filenames with “Filename?” repeatedly, until an empty

string is given

2. Prints a string with all the cleaned filenames, separated by

commas, without any spaces between.

Example Console

output

Filename?patient_zero[20150203].txt

Filename?[shn]shn_batch101.csv

Filename?[x264]psa_recording[1280×720].mp4

Filename?

patient_zero.txt,shn_batch101.csv,psa_recording.mp4

CSIT110/CSIT810

# CSIT110/CSIT810 Assignment 2 SOLVED

Original price was: $35.00.$30.00Current price is: $30.00.

## Reviews

There are no reviews yet.