联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2020-04-29 11:26

CSX3001/ITX3001 Fundamental of Computer Programming,

CS1201 Computer Programming I

1

Assumption University

Vincent Mary School of Science and Technology

Practical Final Examination (First Session)

Semester 2/2019

Subject: CSX3001/ITX3001 Fundamentals of Computer Programming,

CS1201 Computer Programming I

Date: 27 April 2020

Time: 13:30-16:30 (3 hours)

A. Thanachai Thumthawatworn (Section 542)


Instructions:

1. This is an open-book online practical examination.

2. You must be online and join MS Team to take this online examination.

3. Read the questions and instructions carefully.

4. There are 2 parts (total 5 questions)

5. All the files (.py .jpg etc.) must be uploaded to the online platform (MS Team, Google Classroom)

as specified by the lecturer. Additionally, all the files must be submitted via email as well.

6. There is a total of six files that you must submit. Five .py files (one for each question) and 1 image

file for question 5.


Marking Scale:

5 questions, 20 marks

Total 20 marks

Marks

Awarded

1 2 3 4 5 Total

Student Name: ___________________________________________ID: _______________________

Total 5 Pages (including this page)

This is to inform that (you may ignore the following instructions)

§ Students are NOT allowed to use Smart Watches in examinations. Should they be brought into examination rooms,

they are required to be placed on the floor under students’ desk or chair.

§ Violators will be subjected to the terms of punishment for violating examination regulations and/or cheating in the

examination.

Other pertinent University’s examination regulations are on the reverse page.

Students are expected to read and strictly observe them while the examination is in progress.

Failure to do so would subject students to the terms of punishments for violating examination regulations and/or

cheating in the examination.

CSX3001/ITX3001 Fundamental of Computer Programming,

CS1201 Computer Programming I

2

Part 1 [Total 4 questions, 12 marks]: The following Python codes/functions may contain errors

or may not produce expected outputs. You must correct codes/functions to generate expected

outputs. For each question, save your code in a separate .py file. File naming format is as follows:

CourseCode_StudentID_Name_SecNo_1PE_2_2019_Q1.py

For example, ITX3001_u6005678_Harry_541_1PE_2_2019_Q1.py

1. (3 marks) The following function, namely separatechar(mystr), aims at separating an input

string into three separate strings; uppercase characters, lowercase character and digits only.

However, the function does contain error(s) and does not produce the expected output. Fix the

code so that the function generates the correct output as shown below.

def separatechar(mystr):

str1 = ''

upper_char = ''

lower_char = ''

digit_char = ''


for i in str1:

if i.isupper():

upper_char.append(i)

elif i.islower():

lower_char.append(i)

elif i.isdigit():

digit_char.append(i)


print(upper_char)

print(lower_char)

print(digit_char)

print('This is question 1.')

str1 = 'Avenger 4 END GAME was released in Year 2019'

separatechar(str1)

str2 = 'I am 109 years old'

separatechar(str2)

Expected outputs

This is question 1.

AENDGAMEY

vengerwasreleasedinear

42019

= = = = = = = =

I

amyearsold

109

* * * * * * * *

CSX3001/ITX3001 Fundamental of Computer Programming,

CS1201 Computer Programming I

3

2. (2 marks) The following Python code should remove any integer number above 50 from list1

and put that number into list2, and remove any integer number below 50 from list2 and put

that number into list1. However, the code is incomplete and does not produce the correct

output.

The input lists are

list1 = [1,3,60,73,7,88,99,13]

list2 = [20,98,100,2,35,40,9]

The output lists are (incorrect output)

[99, 73, 40, 20, 13, 7, 3, 2, 1] ß 99 and 73 should be in list2

[100, 98, 88, 60, 35, 9] ß 35 and 9 should be in list1

Fix the code so that it generates the correct output as follows:

[1, 2, 3, 7, 9, 13, 20, 35, 40]

[60, 73, 88, 98, 99, 100]

list1 = [1,3,60,73,7,88,99,13]

list2 = [20,98,100,2,35,40,9]

i = 0

while i < len(list1):

if list1[i] > 50:


list2.append(list1.pop(i))


i += 1

j = 0

while j < len(list2):

if list2[j] <= 50:


list1.append(list2.pop(j))


j += 1

list1.sort(reverse = True)

list2.sort(reverse = True)

print(list1)

print(list2)

CSX3001/ITX3001 Fundamental of Computer Programming,

CS1201 Computer Programming I

4

3. (2 marks) The following Python function contains error(s). Fix the code in the function so

that this function calculates a sum of all digits that appear in the input sentence. The expected

output for this sentence is 16.

str1 = 'Avenger 4 END GAME was released in Year 2019'

def sumofdigitsfromstring(str1):

sum_digit = 0

for i in str1:

if i.isdigit():

sum_digit += i

print(sum_digit)

sumofdigitsfromstring(str1)

4. (3 marks) The following Python aims to calculate the cumulative value from list1 to list2.

The cumulative are assigned sequentially to each index. However, the function does contain

error(s) and does not produce the expected output. Fix the code so that the function generates

the correct output.

Before entering the loops,

list1 = [1, 2, 3, 4, 5]

list2 = [0, 0, 0, 0, 0]

After entering the loops,

list1 = [1, 2, 3, 4, 5]

list2 = [1, 3, 6, 10, 15]

list1 = [1, 2, 3, 4, 5]

list2 = [0, 0, 0, 0, 0]

for i in range(1, len(list2)):

x = 0

for j in range(1, list1[i]):

x = list1[j]

list2[i] = x

print(f"list2[{i}] = list2[i]")

Expected outputs

list2[0] = 1

list2[1] = 3

list2[2] = 6

list2[3] = 10

list2[4] = 15

CSX3001/ITX3001 Fundamental of Computer Programming,

CS1201 Computer Programming I

5

Part 2 [Total 1 question, 10 marks]: Write a Python code and draw a flowchart of the code. The

flowchart can be drawn using any tool. Students are allowed to draw the flowchart on a paper, take

a snapshot (save it as JPEG file) and upload the file together with the code for a submission. The

image filename must be as follows:

CourseCode_StudentID_Name_SecNo_1PE_2_2019_Q5.jpg

For example, CSX3001_u6666666_Thor_541_1PE_2_2019_Q5.jpg

5. (6 marks for Python code and 4 marks for a flowchart)

With given two lists (as shown below),

Step1, write a Python code to slice these two lists into 2 slices. The given lists’ size is an even

number.

For example,

list1 = [1,2,3,4,5,6,7,8] à [1,2,3,4] and [5,6,7,8]

list2 = [10,20,30,40] à [10,20] and [30,40]

Step2, the code must replace the first slice of the first list with a second slice of the second

list, and replace the second slice of the second list with the first slice of the first list.

For example,

output_list1 à [30,40, 5,6,7,8]

output_list2 à [10,20,1,2,3,4]

Step3, the code then finds the average value for each output list and determines the output list

that has a higher average value. (In this example is output_list1 which average is 16)

Step4, the code prints all integer numbers that are greater than the average value (only from

the output list that has a higher average value). For example, 30 and 40 from output_list1 will

be printed.

Finally, you must draw a flowchart for your code. Variable names used in the flowchart must

be the same as the one that you use in the code.

You must write the code without using ‘+’ operator on list. In other word,

you are not allowed to concatenate two lists using ‘+’ operator.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp