Python Programming Question

Assignment Task

Part A (10 marks):

Write a program that loops, prompting the user for their full name, their exam result (an integer between 1 and 100), and then writes that data out to file called ‘customers.txt’. The program should check inputs for validity according to the following rules:

  • First and last names must use only alphabetical characters. No spaces, hyphens or special characters. Names must be less than 20 characters long.
  • Exam result (an integer between 1 and 100 inclusive)

The file should record each customers information on a single line and the output file should have the following appearance.

Nurke Fred 58

Cranium Richard 97

Write a second program that opens the ‘customers.txt’ file for reading and then reads each record, splitting it into its component fields and checking each field for validity.

The rules for validity are as in your first program, with the addition of a rule that specifies that each record must contain exactly 3 fields.

Your program should print out each valid record it reads.

The program should be able to raise an exception on invalid input, print out an error message with the line and what the error was, and continue running properly on the next line(s).

You need to develop the system by completing the following three tasks:

Task 1 -

Draw flowchart/s that present the steps of the algorithm required to perform the tasks specified.

Task 2 -

Select at least six sets of test data that will demonstrate the 'normal' operation of your program; that is, test data that will demonstrate what happens when a VALID input is entered.

Note: for this program valid normal input INCLUDES data that does NOT conform to the rules specified. This is because it is the function of your program to DETECT such erroneous data.

Select at least four sets of test data that will demonstrate the 'abnormal' operation of your program. For these programs this might include the inability to write to the output file, or in the case of the second program the inability to open the file.

Set your test results out in a tabular form as follows: test data type, test data, the reason it was selected, the output expected due to using the test data, and finally the output actually observed when the test data is used. It is important that the output listings (i.e., screenshots) are not edited in any way.

Test Data Table

Test data type

Test data

The reason it was selected

The output expected due to the use of the test data

The screenshot of the actual output when the test data are used

Task 3 -

Implement your algorithm in Python. Comment on your code as necessary to explain it clearly.

In addition, for this exercise, use multiple functions, instead of using a single function to do everything. Create a good design of the functions to make the best use of the code and avoid duplication.

You also need to design your program so that it has components that can be reused in another program if needed. Handle exceptions appropriately and use appropriate data structures.

Run your program using the test data you have selected and complete the test data table above.

Part B (5 marks):

To play the PowerBall lottery, you buy a ticket that has five unique numbers in the range of 1–69, and a “PowerBall” number in the range of 1–26. (You can pick the numbers yourself, or you can let the ticket machine randomly pick them for you.) Then, on a specified date, a winning set of numbers is randomly selected by a machine. If your first five numbers match the first five winning numbers in any order, and your PowerBall number matches the winning Pow-erBall number, then you win the jackpot, which is a very large amount of money. If your numbers match only some of the winning numbers, you win a lesser amount, depending on how many of the winning numbers you have matched.

In the student sample programs for this book, you will find a file named pbnumbers.txt, containing the winning PowerBall numbers that were selected between February 3, 2010 and May 11, 2016 (the file contains 654 sets of winning numbers). Figure 8-6 shows an example of the first few lines of the file’s contents. Each line in the file contains the set of six numbers that were selected on a given date. The numbers are separated by a space, and the last number in each line is the PowerBall number for that day. For example, the first line in the file shows the numbers for February 3, 2010, which were 17, 22, 36, 37, 52, and the PowerBall number 24.

Write a program that works with this file to display the 10 most common numbers, ordered by frequency.

Your submission will consist of:

  1. Your algorithm through flowchart/s.
  2. The table recording your chosen test data and results (it can be in a Word or PDF file)
  3. Source code for your Python implementation

Rationale

This assessment task will assess the following learning outcome/s:

  • be able to explain the steps involved in a disciplined approach to problem-solving, algorithm development and coding.
  • be able to demonstrate and explain elements of good programming style.
  • be able to identify, isolate and correct errors in all phases of the programming process.
  • be able to interpret algorithms and program code.
  • be able to apply sound program analysis, design, coding, debugging, testing and documentation techniques to simple programming problems.
  • be able to write code in an appropriate coding language.
  • be able to examine, recognise and be aware of alternate programming approaches to include a broad discussion of procedural and object oriented approaches.

This assessment task is designed to reinforce topic material related to simple functions, files, exceptions and lists.

Marking criteria and standards

Part A:

Criteria

High Distinction (85-100%)

Distinction (75-84%)

Credit (65-74%)

Pass (50-64%)

Fail (0-49%)

Explain the steps involved in a disciplined approach to problem-solving, algorithm development and coding, demonstrate elements of good programming style

(two marks allocated)

Flowchart/s design is well planned, neat, do not have any unnecessary components and free of errors.

Flowchart/s follow convention, free of errors, and they produce the algorithm correctly.

Flowchart/s follow convention and produce the algorithm correctly.

Flowchart/s follow the convention and contain three or less errors

Flowchart/s follow the convention, but contain more than three errors

Identify, isolate and correct errors in all phases of the programming process

Apply sound program analysis, design, coding, debugging, testing and documentation techniques to simple programming problems

(two marks allocated)

Test data explore every branch of the program. Clear explanation is provided of the expected output of the test results.

AND

The presented test output is in the form specified in the assignment.

Sound reasons are provided for the selection of test data.

AND

The test output is correct for any test data in addition to those used in the submitted table to report the test result.

Selected test data present both normal and abnormal data.

AND

The presented test output is correct.

Selected test data are clearly presented in a table and allow easy calculation of output.

AND

The presented test output matches the actual results that can be obtained from the execution of the program.

Selected test data are not clearly presented in a table and/or do not allow easy calculation of output.

Or

The presented test output does not match the actual results that can be obtained from the execution of the program.

Apply sound program analysis, design, coding, debugging, testing and documentation techniques to simple programming problems

Interpret algorithms and program code,

Write code in appropriate language

(six marks allocated)

Python code is produced and contains only necessary statements and variables. Exceptions and errors are handled properly.

Python code for insert is produced and executes properly without any syntax errors. It produces correct results.

Python code for student and assessment management is produced and executes properly without any syntax errors. It produces correct results.

It is fully documented with appropriate comments and all variable names are meaningful.

It uses appropriate data structure.

Python code is produced and implements the flowchart/s consistently.

It uses multiple functions effectively.

It uses a good design of functions to avoid duplicate calculations.

It has components that are reusable.

Python code is produced and does not execute properly. It may contain syntax errors and/or produce incorrect results.

Additional Comments: The standards outlined for each criteria are cumulative. So, for example, to achieve the standard for high distinction your work needs also to meet the standards outlined for Pass, Credit and Distinction.

Part A:

Criteria

High Distinction (85-100%)

Distinction (75-84%)

Credit (65-74%)

Pass (50-64%)

Fail (0-49%)

Apply sound program analysis, design, coding, debugging, testing and documentation techniques to simple programming problems

Interpret algorithms and program code,

Write code in appropriate language

(five marks allocated)

Python code is produced and contains only necessary statements and variables. Exceptions and errors are handled properly.

Python code for insert is produced and executes properly without any syntax errors. It produces correct results.

Python code for student and assessment management is produced and executes properly without any syntax errors. It produces correct results.

It is fully documented with appropriate comments and all variable names are meaningful.

It uses appropriate data structure.

Python code is produced and implements the flowchart/s consistently.

It uses multiple functions effectively.

It uses a good design of functions to avoid duplicate calculations.

It has components that are reusable.

Python code is produced and does not execute properly. It may contain syntax errors and/or produce incorrect results.

Additional Comments: The standards outlined for each criteria are cumulative. So, for example, to achieve the standard for high distinction your work needs also to meet the standards outlined for Pass, Credit and Distinction.

Presentation

You have to prepare and present all source code, test data table, and flowchart/s separately and include them all in a single MS Word file identified by your name. See the 'Requirements' section below. The Python source code you write should be saved with a name such as ITC106assignment2YourName.py and then include a copy of it as text in the MS Word file named ITC106assignment2YourName.docx.

The other parts of the assignment (such as your flowchart/s and your table of test data) should be included in the same MS Word file and save as ITC106assignment2YourName.docx.

It is critically important that your test runs are unmodified outputs from your program, and that these results should be reproducible by the marker running your saved ITC106assignment2YourName.py python program.

Requirements

You have to save all the parts of the assignment (as described under 'Presentation' above) into a single MS Word document identified by your name as outlined in the section on presentation.

Failure to adhere to these requirements may disqualify the submission for marking.

Submit your complete assignment in MS Word format to Turnitin and e-mail your program source code to your subject lecturer (to an e-mail address given by the subject lecturer)

citation generator
citaion generator
make money online