Anne Dawson: CSCI120A_LAB3A_FA08.htm   

 

Last updated: Sunday 21st September 2008, 8:22 PT

 

 

 

CSCI120A

 

Introduction to Computer Science and Programming using Python

Fall 2008

This lab is not an assessed lab, i.e. it will not be marked.

 

You can ask for help at any time.

 

Complete as much as you can in class time,

 

then upload the file to the network folder:

 

CSCI on Pineapple\Anne Dawson\CSCI120A\Week03\LAB3A

 

by end of class today -

 

If you don't complete the assignment in class time,

try to complete it at home.

 

 

 

Lab Assignment 3A

 

 

 

Step 1

 

Study the following:

 

Note: you don't type in the code of your program until Step 4.

Fire Department Calculations

Coquitlam College hosts a student dance every year. Because of fire department regulations, every ballroom has a maximum capacity of people. Since all  college employees (instructors and office staff) attend the dances, this means that  the number of students that can attend the dance is the maximum capacity minus the number of college employees.

 

When your program runs, it will first ask the user to enter the maximum room capacity of the ballroom, (e.g. 300) and then the number of college employees (e.g. 88), and the number of students who want to attend the dance (e.g. 204). If the total number of people is less than or equal to the maximum capacity, then the program should output the message: "The dance may take place with (output the total number) people", and also outputs the number of spare tickets available (if any). If the total number of people exceeds the maximum ballroom capacity, the program should output the message: "The dance may not take place with (output the total number) people", and also outputs the number of people to be excluded to fulfill the fire regulations maximum capacity. A more advanced version of this program will allow the user the option to repeat the program if they wish.  To complete this Python program you will need to use selection (if) statements.

 

Click below for help on:

 

Data types and Processing

Processing and Selection

 

Ask your instructor for help if you need further clarification.

 

You are encouraged to ask questions!

 

 

 

 

Example program input and output:

 

Note: user input is in bold black text, output is in blue text.

 

 

 

Example 1

 

 

Please enter the maximum room capacity:

300

Please enter the number of college employees:

88

Please enter the number of students wanting to attend the dance:

204

 

The dance may take place with 292 people.

 

There are 8 spare tickets available for sale.

 

 

 

Example 2

 

Please enter the maximum room capacity:

275

Please enter the number of college employees:

82

Please enter the number of students wanting to attend the dance:

312

 

The dance may not take place with 394 people.

 

119 people must be excluded because

the fire regulations maximum capacity is 275 people.

 

 

 

 

 

Step 2

 

With pen and paper, design an algorithm (the steps to solve the problem). If you don't fully understand the problem, you will not be able to design the solution. If the problem is not clear, ask your instructor to explain exactly what your program has to do.  Remember that if you get the algorithm and pseudocode steps right, (i.e. your design is good) then your program is very much more likely to be correct first time. You should have the algorithm checked by your instructor before going on to the next step.

 

The following web page will help you design your algorithm:

Algorithms.htm

 

Step 3

 

Development the pseudocode from your algorithm.

 

The following web page will help you design your pseudocode:

Pseudocode.htm

 

Step 4

 

Using your pseudocode as a guide, implement your program in the Python language. Use the IDLE GUI to edit and run your program:

Python_Editor_IDLE.htm 

 

If you've written your pseudocode well, you should be able to convert each line of your pseudocode into a Python statement.

 

Hint: When you start to type in your program, do a little bit at a a time. Write a few lines of Python code and test the program thoroughly before adding a few more lines of code. Don't try to do it all at once - that would guarantee failure. Do a little bit at a a time.  Add extra print statements to print out the values of variables as your program runs, so that you know at every stage what values are stored. Use meaningful variable names; for example, if you need a variable to store the maximum room capacity, use the variable name max_capacity rather than a variable name like max, or worse, x. Names like max or x don't really give you much clue about the purpose of the value they contain. Using meaningful variable names make your programs more readable and thus more easier to understand - and easier to extend. For more good programming tips, check out this webpage:

 

 

 

Your program should start with a comment block that contains the following information:

 

#  File:       yourstudentnumber.py

#  Purpose:    Lab 3B - Fire Department Calculations

#  Programmer: [your name]

#  Course:     CSCI120A

#  Date:       Monday 22nd September 2008

#  Test data:  [data showing how you tested your program]

 

Please note: any lines in a Python program that start with the # symbol are known as comments. Comments are ignored when the program runs, but are useful when we read a program, because they supply information about the program. Comments are your friend. They're always used at the top of a program to supply information about the purpose of a program; its file name, the programmer etc, as shown above. They're also used in the body of a program to explain parts of the program which may be hard for the reader to understand. Example programs in this course will demonstrate the correct use of comments. You're expected to supply the above set of comments (updated appropriately) for all of your lab and homework programming assignments.

 

Step 5

 

Test your program by running supplying your own test data. You should test your program with at least 3 sets of test data. Show your test data and results in comments at the top of your program.

 

Step 6

 

Before the end of the class, follow these instructions to copy your program file (yourstudentnumber.py) - (just your Python file - no folders please), to :

 

CSCI on Pineapple\Anne Dawson\CSCI120A\Week03\LAB3B

 

 

The following marking scheme is just a guide to illustrate how this program would be marked if it was an assessed lab.  Note that 45% of the points are awarded for design and style.  Only 25% of the marks are awarded for a complete and tested program! 

 

Marking Scheme: CSCI120A   -   Lab 3A  -   Fire Department Calculations

Marking Scheme

Category

Points

Description

Comments

10

The program should be commented as specified in this document.

algorithm

15

An informal description of the steps that must be taken to solve the problem. The algorithm should be included in comments in your source code file (studentnumber.py).

pseudocode

15

A formal description of the steps that must be taken to solve the problem. The pseudocode should be included in comments in your source code file (studentnumber.py).

Output

10

Screen prompts and results should be user-friendly.

Correctness

10

The program should do what is required.

Completeness

10

The program should be complete.

Style

15

The source code should use meaningful variable names.

Test

15

Comments in the code explain how the code was tested.