辅导ENG5322编程、讲解Python留学生编程、Python程序设计调试
- 首页 >> Python编程 ENG5322: Civil Engineering Skills M
Computer programming class test
10th November 2020
Instructions:
● You are given 90mins to complete all questions.
● The test comprises of 3 questions each with 20 marks available for each (60 total).
● When finished, you must submit your complete Python notebook (.ipynb file) through
the test submission page on Moodle, along with pasted solution in a word document.
● This is an open book test and therefore you are free to use lecture and lab notes.
● You must not confer with other students during the test.
Good luck!
Question 1 (20 marks)
An engineer has performed various measurements on different materials with the values
given as follows:
matA [194.7, 215.2, 200.5, 197.3, 205.3]
matB [65.5, 73.4, 71.2, 68.5, 75.8, 66.9]
matC [23.4,34.5,45.6,27.5,56.5,45.5,47.9]
matD [110.4, 103.5, 129.4, 115.4, 123.2, 110.2]
Create a dictionary from the above data which uses the material name as the key and the
experimental data as the corresponding list. Write some code which loops over this
dictionary and outputs the mean and 50 percentile for this list in the format where XX below
are the respective values
Specimen: matA
Mean: XX
50 percentile: XX
Specimen: matB
Mean: XX
50 percentile: XX
Specimen: matC
Mean: XX
50 percentile: XX
….
[5 marks]
Write some code which gives overall mean and 50 percentile for all the data
Specimen: all_specimens
Mean: XX
50 percentile: XX
[5 marks]
Write some code which creates a second dictionary that comprises of the same materials
but has an additional specimen, for example, “matE”. You should write the logic to populate
the values for this material in a loop until the user types the word “stop”.
[5 marks]
Finally, produce a bar chart of each material type and its reading. Label your axes
accordingly.
[5 marks]
Question 2 (20 marks)
You are asked to write a program that models the vibration of a cantilever beam. The
displacement of the beam is given by the following function:
Those with the numeric digits of the student IDs add up to an even number will attempt:
u(t) = cos(kt)e−0.2t
Those with the numeric digits of the student IDs add up to an odd number will attempt:
u(t) = sin(kt)e−0.2t
where u is the displacement of the beam, k is a vibration constant and t is the time variable.
Your first task is to write a function that takes two arguments: k and t and returns the above
function as an output.
[4 marks]
Using the function that you have just written, write file outputs for beam displacement where
k=0.1, and t varies from 0.0 to 20π in steps of 0.2. Make sure that while outputting the file,
the file follows the following structure:
t,k
0.0,0.0
0.2,0.194
….
[6 marks]
Next task is that once you are done generating the file, read from the file and write logic to
create two empty lists, t_list, and k_list, and then populate these lists with the values from
list, and print them on the screen:
Hint:
t_list=[]
k_list=[]
for line in file:
record=line.split(“,”)#i.e., splitting line into a list
# record[0] contains t
# record[1] contains k
# other logic comes here to populate t_list, and k_list
[5 marks]
Finally, for k=0.3, plot the vibration of the beam between 0.0 and 10π using steps of 0.01.
Label your axes accordingly.
[5 marks]
Question 3 (20 marks)
You are asked to produce a program for analysing river level readings which are taken on a
daily basis. The engineer has already taken a set of readings given by:
8.3, 7.3, 3.9, 4.5, 4.9, 6.2, 5.2, 5.6, 10.1, 2.4, 8.9, 4.7, 11.2, 2.5, 4.8
New readings have been taken of:
and the engineer has requested that these are added to the existing set of readings. Write
some code which creates the list of existing readings, adds the new values to the list and
then sorts the list in ascending order. Please note that the readings should be supplied in a
loop as a user input until the user types ‘end’.
[5 marks]
The engineer wants the data to be sorted into two lists:
• Those with the numeric digits of the student IDs add up to an even number will
attempt:
readings that lie between the plus or minus 10% of the average of all readings
Those with the numeric digits of the student IDs add up to an odd number will
attempt:
readings whose values are between 10% and 20% of the average
● and a final list containing all other readings
These above lists should be printed to the screen.
[10 marks]
Finally, he wants a line plot containing all the river level readings. This should contain
relevant axis labels.
[5 marks]
Computer programming class test
10th November 2020
Instructions:
● You are given 90mins to complete all questions.
● The test comprises of 3 questions each with 20 marks available for each (60 total).
● When finished, you must submit your complete Python notebook (.ipynb file) through
the test submission page on Moodle, along with pasted solution in a word document.
● This is an open book test and therefore you are free to use lecture and lab notes.
● You must not confer with other students during the test.
Good luck!
Question 1 (20 marks)
An engineer has performed various measurements on different materials with the values
given as follows:
matA [194.7, 215.2, 200.5, 197.3, 205.3]
matB [65.5, 73.4, 71.2, 68.5, 75.8, 66.9]
matC [23.4,34.5,45.6,27.5,56.5,45.5,47.9]
matD [110.4, 103.5, 129.4, 115.4, 123.2, 110.2]
Create a dictionary from the above data which uses the material name as the key and the
experimental data as the corresponding list. Write some code which loops over this
dictionary and outputs the mean and 50 percentile for this list in the format where XX below
are the respective values
Specimen: matA
Mean: XX
50 percentile: XX
Specimen: matB
Mean: XX
50 percentile: XX
Specimen: matC
Mean: XX
50 percentile: XX
….
[5 marks]
Write some code which gives overall mean and 50 percentile for all the data
Specimen: all_specimens
Mean: XX
50 percentile: XX
[5 marks]
Write some code which creates a second dictionary that comprises of the same materials
but has an additional specimen, for example, “matE”. You should write the logic to populate
the values for this material in a loop until the user types the word “stop”.
[5 marks]
Finally, produce a bar chart of each material type and its reading. Label your axes
accordingly.
[5 marks]
Question 2 (20 marks)
You are asked to write a program that models the vibration of a cantilever beam. The
displacement of the beam is given by the following function:
Those with the numeric digits of the student IDs add up to an even number will attempt:
u(t) = cos(kt)e−0.2t
Those with the numeric digits of the student IDs add up to an odd number will attempt:
u(t) = sin(kt)e−0.2t
where u is the displacement of the beam, k is a vibration constant and t is the time variable.
Your first task is to write a function that takes two arguments: k and t and returns the above
function as an output.
[4 marks]
Using the function that you have just written, write file outputs for beam displacement where
k=0.1, and t varies from 0.0 to 20π in steps of 0.2. Make sure that while outputting the file,
the file follows the following structure:
t,k
0.0,0.0
0.2,0.194
….
[6 marks]
Next task is that once you are done generating the file, read from the file and write logic to
create two empty lists, t_list, and k_list, and then populate these lists with the values from
list, and print them on the screen:
Hint:
t_list=[]
k_list=[]
for line in file:
record=line.split(“,”)#i.e., splitting line into a list
# record[0] contains t
# record[1] contains k
# other logic comes here to populate t_list, and k_list
[5 marks]
Finally, for k=0.3, plot the vibration of the beam between 0.0 and 10π using steps of 0.01.
Label your axes accordingly.
[5 marks]
Question 3 (20 marks)
You are asked to produce a program for analysing river level readings which are taken on a
daily basis. The engineer has already taken a set of readings given by:
8.3, 7.3, 3.9, 4.5, 4.9, 6.2, 5.2, 5.6, 10.1, 2.4, 8.9, 4.7, 11.2, 2.5, 4.8
New readings have been taken of:
and the engineer has requested that these are added to the existing set of readings. Write
some code which creates the list of existing readings, adds the new values to the list and
then sorts the list in ascending order. Please note that the readings should be supplied in a
loop as a user input until the user types ‘end’.
[5 marks]
The engineer wants the data to be sorted into two lists:
• Those with the numeric digits of the student IDs add up to an even number will
attempt:
readings that lie between the plus or minus 10% of the average of all readings
Those with the numeric digits of the student IDs add up to an odd number will
attempt:
readings whose values are between 10% and 20% of the average
● and a final list containing all other readings
These above lists should be printed to the screen.
[10 marks]
Finally, he wants a line plot containing all the river level readings. This should contain
relevant axis labels.
[5 marks]