Вы находитесь на странице: 1из 8

ITC106 Programming Fundamentals

Assignment 2A&2B

Submitted by : Li Zhu
Student id : 11454596
Assignment 2A
1a.Structured English Algorithm
BEGIN
Define main function
Print information message
Open a file for writing
Prompt for players name and score
Write the data as a record to the file
Close the file
Print the players records written to the file golf.txt
Call the main function
END

2a. Test Data (Normal)


Test Data

Reason

Expected Output

Actual
Output

Tom

Select a name

90

Julie
89

Select a name

name:Tom

name:Tom

score:90

score:90

player records written to

player records written to

the golf.txt.

the golf.txt.

name:Julie

name:Julie

score:89

score:89

player records written to

player records written to

the golf.txt.

the golf.txt.

3a. Test Data (Abnormal)


Test Data

Reason

Expected Output

Actual
Output

Tom

Value is not a integer

error

error

Negative value

error

name:Lily

89.9
Lily
-89

score:-89
player records written to
the golf.txt.

4a. Program
Contained in file playerfile.py

5a. Program outputs


>>>
name:Tom
score:90
player records written to the golf.txt.
>>> main()
name:Julie
score:89
player records written to the golf.txt
>>>
name:Tom
score:89.9
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\palyerfile.py", line 26, in <module>
main()
File "C:\Users\Administrator\Desktop\palyerfile.py", line 12, in main
score=int(raw_input('score:'))
ValueError: invalid literal for int() with base 10: '89.9'
>>> main()
name:Lily

score:-89
player records written to the golf.txt.
1b.Structured English Algorithm
BEGIN
Define main function:
Print information message
Input the name of a file
Open the file
Read the first line (name)of the file
Read the score
Strip the line from the fields
Output the:
Name
Score
Close the file
Call the main function
END

END

2b. Test Data (Normal)


Test Data

Reason

Expected Output

Actual
Output

golf.txt

golf.txt

File name

File name

Enter a filename:golf.txt

Enter a filename:golf.txt

Name: Tom

Name: Tom

Score: 90

Score: 90

Enter a filename:golf.txt

Enter a filename:golf.txt

Name: Julie

Name: Julie

Score: 89

Score: 89

3b. Test Data (Abnormal)


Test Data

Reason

Expected Output

Actual
Output

Player.txt

Wrong file name

error

Enter

filename:player.txt
An

error occured trying

to read the file.


Game.txt

Wrong file name

error

Enter

filename:player.txt
An

error occured trying

to read the file.

4b. Program
Contained in file readgolf.py

5b. Program outputs


>>>
Enter a filename:golf.txt
Name: Tom
Score: 90
>>> main()
Enter a filename:golf.txt
Name: Julie
Score: 89
>>> main()
Enter a filename:player.txt
An

error occured trying to read the file.

>>> main()
Enter a filename:game.txt
An

error occured trying to read the file.

>>>

Assignment 2B
1.Structured English Algorithm
BEGIN
Define the main function:
Prompt the information message

Open a file for reading


Read the contents of the file into a list
C lose the file
Strip the \n from each element
Input:
While account is empty over the loop
The account number
Output:
The charge account number
If the input account number is in the charge_account print: it is a valid account number
If the input account number is not in the charge_account print: it is a invalid account number
Call the main function
END

2. Test Data (Normal)


Test Data

Reason

Expected Output

Actual
Output

5658845

4520125

The account number is in

['5658845',

'4520125',

['5658845',

'4520125',

the charge_account file

'7895122',

'8777541',

'7895122',

'8777541',

'8451277',

'1302850',

'8451277',

'1302850',

'8080152',

'4562555',

'8080152',

'4562555',

'5552012',

'5050552',

'5552012',

'5050552',

'7825877',

'1250255',

'7825877',

'1250255',

'1005231',

'6545231',

'1005231',

'6545231',

'3852085',

'7576651',

'3852085',

'7576651',

'7881200', '4581002']

'7881200', '4581002']

enter the charge account

enter the charge account

number:5658845

number:5658845

It is a valid account

It is a valid account

number.

number.

enter the charge account

enter the charge account

number:

number:

It is a invalid account

It is a invalid account

number.

number.

The account number is in

['5658845',

'4520125',

['5658845',

'4520125',

the charge_account file

'7895122',

'8777541',

'7895122',

'8777541',

'8451277',

'1302850',

'8451277',

'1302850',

'8080152',

'4562555',

'8080152',

'4562555',

'5552012',

'5050552',

'5552012',

'5050552',

'7825877',

'1250255',

'7825877',

'1250255',

'1005231',

'6545231',

'1005231',

'6545231',

'3852085',

'7576651',

'3852085',

'7576651',

'7881200', '4581002']

'7881200', '4581002']

enter the charge account

enter the charge account

number:4520125

number:4520125

It is a valid account

It is a valid account

number.

number.

enter the charge account

enter the charge account

number:

number:

It is a invalid account

It is a invalid account

number.

number.

Expected Output

Actual

3. Test Data (Abnormal)


Test Data

Reason

Output
7878787

The account number is

error

['5658845',

'4520125',

not in the charge_account

'7895122',

'8777541',

file

'8451277',

'1302850',

'8080152',

'4562555',

'5552012',

'5050552',

'7825877',

'1250255',

'1005231',

'6545231',

'3852085',

'7576651',

'7881200', '4581002']
enter the charge account
number:7878787
It is a invalid account
number.
enter the charge account
number:
It is a invalid account
number.
90909090

The account number is

error

['5658845',

'4520125',

more than seven digit

'7895122',

'8777541',

number

'8451277',

'1302850',

'8080152',

'4562555',

'5552012',

'5050552',

'7825877',

'1250255',

'1005231',

'6545231',

'3852085',

'7576651',

'7881200', '4581002']
enter the charge account
number:90909090
It is a invalid account
number.
enter the charge account
number:
It is a invalid account
number.

4a. Program
Contained in file playerfile.py

5. Program outputs
>>>
['5658845', '4520125', '7895122', '8777541', '8451277', '1302850', '8080152', '4562555', '5552012', '5050552',
'7825877', '1250255', '1005231', '6545231', '3852085', '7576651', '7881200', '4581002']
enter the charge account number:5658845
enter the charge account number:5658845
It is a valid account number.
enter the charge account number:
It is a invalid account number.
>>> main()
['5658845', '4520125', '7895122', '8777541', '8451277', '1302850', '8080152', '4562555', '5552012', '5050552',
'7825877', '1250255', '1005231', '6545231', '3852085', '7576651', '7881200', '4581002']
enter the charge account number:4520125
enter the charge account number:4520125
It is a valid account number.
enter the charge account number:
It is a invalid account number.
>>> main()
['5658845', '4520125', '7895122', '8777541', '8451277', '1302850', '8080152', '4562555', '5552012', '5050552',
'7825877', '1250255', '1005231', '6545231', '3852085', '7576651', '7881200', '4581002']
enter the charge account number:7878787
enter the charge account number:7878787
It is a invalid account number.
enter the charge account number:
It is a invalid account number.
>>> main()
['5658845', '4520125', '7895122', '8777541', '8451277', '1302850', '8080152', '4562555', '5552012', '5050552',
'7825877', '1250255', '1005231', '6545231', '3852085', '7576651', '7881200', '4581002']

enter the charge account number:90909090


enter the charge account number:90909090
It is a invalid account number.
enter the charge account number:
It is a invalid account number.
>>>

Вам также может понравиться