Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

BIT100 Assignment 1

Due date:
Value: 10%
Assessment Mode: Individual Assessment
Rationale
This assignment is designed to reinforce the subject material covered in the learning modules
and encourage students to work consistently throughout the semester. This assignment has been
designed to give students the opportunity to demonstrate their skill in:
 writing code to apply basic Python statements;
 passing arguments to functions and capturing the return value;
 designing applications that require user interaction;
 using good programming style.

The assignment assesses the following learning outcomes


 explain the steps involved in a disciplined approach to problem-solving, algorithm
development and coding;
 discuss elements of good programming style;
 identify, isolate and correct errors in all phases of the programming process;
 write code in an appropriate coding language

SUBMISSION REQUIREMENT
Your assignment has to submit to TurnItIn, with the following all contain in a single file:
1. All your Python source files, printed in Word document format
2. Printed output (showing your interactivity with your program) is to be included at the end of
your Python source files, in Word document created in (1)
3. A Turnitin Report, again to be attached within the Word document created in (1)

Turnitin Report (http://www.turnitin.com)


Register yourself in intro2ProgSF19 using the following details:
class ID : 20488088
Enrollment password: SF19Python

Question 1 (20 marks)


Write a program that will calculate and print bills for the city power company. The rates vary
depending on whether the use is residential, commercial, or industrial. A code of R means
residential use, a code of C means commercial use, and a code of I means industrial use.
The rates are computed as follows:
R: RM6.00 plus RM0.052 per kwh used
C: RM60.00 for the first 1000 kwh and RM0.045 for each additional kwh
I: Rate varies depending on time of usage:
Peak hours: RM76.00 for first 1000 kwh
and RM0.065 for each additional kwh
Off peak hours: RM40.00 for first 1000 kwh
and RM0.028 for each additional kwh.
Your program should prompt the user to enter an integer account number, the use code, and the
necessary consumption figures in whole numbers of kilowatt-hours. Note that if the code is I, an
additional input to determine whether it is peak or off peak is required.
Your program should display the amount due from the user.
NOTE: Your program should use loop to validate
i) the code, if user does not enter ‘R’, ‘C’, or ‘I”, then the program should repeatedly prompt
for valid code.
ii) the usage – make sure that the usage is not negative.

Question 2 (20 marks)


(a) Write a program that prompts user to enter two words, and display the positions of the first
occurrence of common letter in both words. For example, if the words entered are
‘assignment’ and ‘examination’ respectively, then the first common letter is ‘a’, and the
positions printed are 1 and 3 respectively. If there is no common letter between the words, for
example, ‘private’ and ‘school’, then display an appropriate message to inform user about
this.
NOTE: We will use the letters of the first word to check against the letters in the second
word, and NOT the other way round. So, for example, if the words entered now are
‘Examination’ and ‘assignment’ in that order, then the first common letter now is ‘e’,
and the positions printed are 1 and 8 respectively.
(b) Enhanced the program in (a) by displaying the words as word-cross. For the words above, the
display would look like the following:
assignment Examination PYTHON private
examination assignment Common school
EXAMINATION ASSIGNMENT P An appropriate message
S X Y informing user that there is
S A T
I M H no common letters between
G I COMMON the words
N N N
M A
E T
N I
T O
N
NOTE: i) The first word will be displayed vertically, whereas the second is displayed
horizontally.
ii) The comparison should ignore the case, that is E and e should be considered the
same.

Question 3 (25 marks)


a) A function called zap which accepts any positive integer parameter and returns the sum of
the squares of its digits. For example,
zap( 73 ) will return 58 because 72 + 32 = 58
zap( 4 ) will return 16 because 42 = 16
b) If we keep zapping the result of a previous zap, we generate a sequence of integers which
will eventually produce either 1 or 4. For example, if we start with 73:
zap( 73 )  58 or, if we start with 44:
zap( 58 )  89 zap( 44 )  32
zap( 89 )  145 zap( 32 )  13
zap( 145 )  42 zap( 13 )  10
zap( 42 )  20 zap( 10 )  1
zap( 20 )  4
Numbers which zap to 1 are called 'Happy Numbers' and those which zap to 4 are called
'Unhappy Numbers'. Write a boolean function called happy which takes an integer and
determines if it is happy or not.
c) i) Write a complete program which allows user to enter a positive integer number, n, and
display all the happy numbers up to n.
ii) Write a complete program which locates all the pairs of consecutive happy numbers
between 1 and 1000. Such pairs are called 'lovers'.

Question 4 (20 marks)


(a) A year is a leap year if it is divisible by 400 or if it divisible by 4 but is not divisible by 100.
(1800 and 1900 are not leap years while 1600 and 2000 are.) Write a function that accepts an
integer parameter, and determines whether the parametric year is a leap year, that is the
function should return a bool value.
(b) Write a function that accepts a string that represent a date in the form day/month/year, and
determines whether or not the date is valid, that is the function should return a bool value.
For example 24/5/1962 is valid, but 31/9/2000 and 29/2/1997 are not. (September has only
30 days, and 1997 is not a leap year.)
(c) The days of the year are often numbered from 1 through 365 (or 366). This number can be
computed in three steps using integer arithmetic:
i. dayNum = 31(month – 1) + day
ii. if the month is after February subtract (4month+23)/10
iii. if it is a leap year and after February 29, add 1
Write a program that accepts a date as day/month/year, verifies that it is a valid date (see (b)
above) and then calculates the corresponding day number.
HINT: If possible you should employ functions within modules for code re-use, and thus reduce
duplication of code.

Documentation
 You should include comments in your code stating what each function does and explaining
any complex sections of code.
 You should also include your student ID and name as comments within the code.
 You should of course use meaningful variable names so that your code is to some extent self-
documenting.
What to Submit
You should submit the following:

 A cover-sheet stating your name and student number.


 Printouts of your source code using Courier-New 10-point size font. Make sure that your
long Python statements, if any, do not have the second line printed starting from the left-hand
margin. You must break the long statement in appropriate length.
 You are NOT allowed to print in landscape orientation.
 Printouts demonstrating real interaction between yourself and your application
 And a compressed file containing the source files .py uploaded to elearning.
 Upload your program code, together with sample output, in Word format, to turnitin.com

Marking Scheme
Question 1 requirements completed with correct results 20 marks
Question 2 requirements completed with correct results 20 marks
Question 3 requirements completed with correct results 25 marks
Question 4 requirements completed with correct results 20 marks
Assignment presentation, quality of code and documentation 15 marks
NOTE: Refer to the Excel file, A1100MS_SF19.xlsx, for detailed breakdown of the marks
allocated.

Note about marking

There will be no marks for almost meeting the requirements of a particular level. In order to
obtain the marks for a given level, you must demonstrate that your program produces the correct
results for the given test data. If you do, you will receive all of the marks indicated above. If you
do not, you will receive no marks.

If your program does not meet the requirements by the due date you should obtain help
from the lecturer and notify the lecturer that you will submit the assignment late (marks
will be deducted).

Note about testing and plagiarism

It is very important that you complete this assignment alone. You may of course obtain general
assistance from the lecturing staff in the subject and your peers, but the coding must be carried
out yourself. It is normally quite easy to detect when two or more students work together on
their coding.

It is also very important that the demonstration of the results of your program using the given test
data is produced using the identical version of the program to the printout of your source code.
Students who hand in substantially similar assignments or whose programs do not match
their demonstration of testing will fail the assignment.

Any student suspected of copying, or of not producing the work himself or herself, can be called
for oral examination, where the student will be expected to demonstrate sufficient knowledge
of the application to show that it is his or her own original work.

You might also like