Lecture notes for the Introduction to Computer Science for non-majors by James Tam Return to the course web page

CPSC 217: Assignment 5 (Worth 6%)

New concepts to be applied for the assignment

  1. Modular implementation of a solution: defining and calling functions
  2. Parameter passing
  3. Function return values

Determining your lucky number

Unless otherwise indicated the features of your program for this assignment are the same as for the previous assignment.

Modules to be implemented for this assignment (you will also be graded on other criteria such as coding style and providing program documentation as listed in the marking key):

Function name

Inputs / parameters

Return value (s)

Description of what the function does

Marks

main

None

None

The starting point of execution for the program.

NA

introduction

None

None

Describe how the program works.  The function runs once as the program first runs.

1

conclusion

None

None

Display a signoff message so that the user knows that the program has ended.

1

askAge

age

age

Prompts the user to enter their age. (1 mark) Reads in the value entered by the user. (1 mark) Determines if the age is outside the allowable range (4 marks) and if so it sets the age to the default value. (1 mark)

7

determineAgeModifier

age

Value for the age modifier

Based on the age entered this function will calculate and return the age modifier.

2

askGender

gender

gender

Prompts the user to enter their gender. (1 mark) Reads in the value entered by the user. (1 mark) Determines if the gender is valid (2 marks) and if not it sets the gender to the default value. (1 mark)

5

determineGenderModifier

gender

Value for the gender modifier

Based on the gender entered this function will calculate and return the gender modifier.

2

askComputer

computer

computer

Prompts the user to enter their computer type. (1 mark) Reads in the value entered by the user. (1 mark) Determines if the computer type is not one of the allowable values (4 marks) and if so it sets the computer to a default value. (1 mark)

7

determineComputerModifier

computer

Value for the computer modifier

Based on the computer type entered this function will determine the value for the computer modifier and return this value back to its caller.

2

generateLuckySum ageModifer,

genderModifier,

computerModifier

Value for the lucky sum This function will return the sum of the three parameters. 2
generateLuckyNumber luckySum Value for the lucky number Based on the calculated lucky sum this function will determine the user's lucky number and return this value back to the caller. 2

Resources available

In the course directory under the path: /home/courses/217/assignments/assignment5 you will find a skeleton program called "lucky.py". You must use this program as the starting pointing for implementing your solution to this assignment. Also if you are having trouble trying to figure out which function is supposed to call which here is a [graphical representation] of all the function calls.

Submission requirements

In addition to having fulfill the generic assignment requirements, the requirements specific to this assignment include:

 
  1. Include a README file in your submission:  For this assignment you need to include a file called 'README' which includes your contact information: your name, university identification number and UNIX login name so that your marker knows whose assignment that he or she is marking.  Also your README should also list which features of the assignment that you completed (in the case of this assignment which functions did you actually impliment).

 
  1. The programming assignments require a two part submission: a) A paper submission of your README file and Python program into the assignment drop boxes (second floor Math Sciences) b) An electronic submission (again of your README file and your Python program) as an email attachment (don't cut and paste it into the email body!) to the following people (failing to include everyone listed below may result in your assignment not being marked for credit so before submitting your assignment double check!) Make sure that the subject line of the email contains the exact text (don't add or delete anything to it or you will lose marks): CPSC 217 Assignment X.

X = The appropriate assignment number (e.g., for Assignment 3 the subject would be titled "CPSC 217 Assignment 3")

 
  1. The course instructor at the following email address: tamj@cpsc.ucalgary.ca
 
  1. Your tutorial instructor, the email addresses for the TA's can be found on the main course web page.
 
  1. The TA coordinating the marking of assignments: amaobied@ucalgary.ca (if you are in Ahmed's tutorial you don't have to send your assignment to him twice, other students must send their assignment both to their TA and to Ahmed).
 
  1. Yourself. Sending the assignment to yourself provides one last "double check" that you submitted your assignment properly (e.g., you sent it to all the right people, you attached all the important files to the submission etc.) When you receive the submitted assignment you can check one last time to make sure that you fulfilled all the requirements. If you forgot something then you can resend your assignment with a note to mark only the latest submission (but try not to resubmit your assignment too many times please).
 
  1. As a reminder, you are not allowed to work in groups for this class.   Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following link.
To help make sure that you haven't missed anything here is a checklist of items to be used in marking.