Академический Документы
Профессиональный Документы
Культура Документы
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
Reason
Expected Output
Actual
Output
Tom
Select a name
90
Julie
89
Select a name
name:Tom
name:Tom
score:90
score:90
the golf.txt.
the golf.txt.
name:Julie
name:Julie
score:89
score:89
the golf.txt.
the golf.txt.
Reason
Expected Output
Actual
Output
Tom
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
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
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
Reason
Expected Output
Actual
Output
Player.txt
error
Enter
filename:player.txt
An
error
Enter
filename:player.txt
An
4b. Program
Contained in file readgolf.py
>>> main()
Enter a filename:game.txt
An
>>>
Assignment 2B
1.Structured English Algorithm
BEGIN
Define the main function:
Prompt the information message
Reason
Expected Output
Actual
Output
5658845
4520125
['5658845',
'4520125',
['5658845',
'4520125',
'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']
number:5658845
number:5658845
It is a valid account
It is a valid account
number.
number.
number:
number:
It is a invalid account
It is a invalid account
number.
number.
['5658845',
'4520125',
['5658845',
'4520125',
'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']
number:4520125
number:4520125
It is a valid account
It is a valid account
number.
number.
number:
number:
It is a invalid account
It is a invalid account
number.
number.
Expected Output
Actual
Reason
Output
7878787
error
['5658845',
'4520125',
'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
error
['5658845',
'4520125',
'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']