0% found this document useful (0 votes)
8 views

Intro to Programming with Python - Midterm Programming

The document outlines the instructions and structure for the Midterm exam in BANA3020 Introduction to Programming with Python, scheduled for November 20, 2020. It includes details on exam duration, allowed materials, submission guidelines, and academic honesty requirements, as well as three programming problems worth a total of 100 points. Each problem focuses on different programming concepts, including string manipulation, a grading system, and functions.

Uploaded by

Thanh Doãn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Intro to Programming with Python - Midterm Programming

The document outlines the instructions and structure for the Midterm exam in BANA3020 Introduction to Programming with Python, scheduled for November 20, 2020. It includes details on exam duration, allowed materials, submission guidelines, and academic honesty requirements, as well as three programming problems worth a total of 100 points. Each problem focuses on different programming concepts, including string manipulation, a grading system, and functions.

Uploaded by

Thanh Doãn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Name:

Student ID:

Midterm – Fall 2024


BANA3020 Introduction to Programming with Python November 20, 2020
(Programming Portion)
Test duration: 2 hours

Instructions:

• Please read each question carefully. You have a total of 120 minutes to complete the
programming part of the exam. You must stop working on the exam and submit your work
by 12:00PM. Otherwise, your test will not be graded. After 9:10AM, the Internet will be
shut down.
• Make sure you have your name on the submitted files as comment lines.
• The programming part of the exam is open book open note exam, no Internet access, no
personal computer.
• You’re not allowed to leave the exam room for any reason. If you need to use the bathroom,
notify the exam proctor by remaining seated and raising your hand. Your proctor will grant
you permission.
• Academic honesty is required in all work you submit to be graded. Any form of cheating
will result in a 0 (zero) for the midterm score.
• You are allowed to bring drafting paper and pencil. We will provide drafting papers.
• Late submission of exam without an approved extension will not be graded.
• You will conduct your exam on a lab computer. Your personal laptop is NOT allowed.
• You should upload your .py file(s) to the Canvas (under Assignments>Midterm Exam (Pro-
gramming Part)) before the end of the exam session. Submit separate .py file for each
problem with the following naming format, for example, M idterm_P 1.py. Note: The only
supported file extension is py.
• Late submissions without an approved extension will not graded at all. You can resubmit
the file multiple times. Your last submission will be graded.
• Good luck!

About the exam: There are three problems with 100 points total, and some have multiple parts.

Midterm - Fall 2024 Page 1


Problem Name Estimated time to complete (including reading time) Point
1 Working with Strings 30’ 30
2 Grading System 40’ 30
3 Functions 50’ 40

Some advice for tackling problems:

• We highly recommend you look over the entire exam before getting started so that you can budget
your time well.

• Please type up your work and write down your ideas by coding, even if you get stuck on a prob-
lem and your program does not work. We can give you partial credit as long as we can understand
what you wrote.

• In this exam, you do NOT need to comment on your functions or every line of code. We will NOT
be grading on coding style.

• If you don’t remember how to use a function or method, try running help(functionName),
help(str.methodName) or help(list.methodName).

Midterm - Fall 2024 Page 2


Problem 1 (30-pts) Working with Strings
Start by asking the user for a sentence using the prompt: "Enter a sentence: ". Your task is to create
a program that performs the following tasks:

- (5-pts) Print out the number of characters and the number of words in this sentence on a single
line using the following format:
"Number of characters is _ and number of words is _"

- (10-pts) Use the function randrange in the module random to pick a random position in the sen-
tence. For example, if the sentence has 8 words, you can call: random.randrange(0,7) to generate
a random position in the sentence. Print "Random position picked: _"
Prompt user to input a string using the prompt: "Enter a string: ". Capitalize the string, and
insert it at the random word position in the sentence with quotation marks ("") around it. Print the
new sentence.

Hint: You can split the string into list of words, and use random.randrange(start,stop) to get a
random integer in that range.

- (10-pts) Remove the quotation marks. Print the final sentence with the ’-’ character replacing
spaces. Hint : You can use a string method str.replace() to replace a character with a specific
character of your choice. Use help(str.replace) to get help on how the function can be used.

Assume the input sentence and string contain only letters (a-z and A-Z), and spaces. The program
output should be similar to the following example:

Enter a sentence: VinUni is a young institution


Number of characters is 29 and number of words is 5
Enter a string: and elite
Random position picked: 4
VinUni is a young "AND ELITE" institution
VinUni-is-a-young-AND-ELITE-institution

The output needs to be formatted exactly as it is shown in the example; otherwise, up to 5 pts will be
deducted.

Midterm - Fall 2024 Page 3


Problem 2 (30-pts) Grading System
Given the number of students and their exam scores. The grade is decided by the following criteria:

• More than or equal to 80 is an A grade.

• More than or equal to 60 is a B grade.

• More than or equal to 40 is a C grade.

• Less than 40 mark is an F grade.

For this problem you need to write down a program for the grading system. Start by asking for the number
of students with the prompt: "Enter the number of students: ".

Using the number of students, ask for the user to input each student’s name and score with the
prompt:
"Enter the name for student number _: ".
"Enter the score for student number _: ".
Save the students into a Python dictionary name it grade_dict whose keys are students’name, values
are students’ letter grade. It should look something like this: ’Mike’:’A’, ’Minh’:’B’,’Lan’:’C’. Of
course, for a dictionary, we need dictionary’s keys to be unique, but we ignore that for now. Print out the
object grade_dict using the function print().
Finally, print out the number of students for each letter grade with the format:
"The number of students in Grade _ is: _".
Assume the user input will always be a number between 0 and 100. The program output should be similar
to the following example:

Enter the number of students: 4


Enter the name for student number 1:Mike
Enter the score for student number 1: 20
Enter the name for student number 2:Minh
Enter the score for student number 2: 80
Enter the name for student number 3:Lan
Enter the score for student number 3: 100
Enter the name for student number 4:Josh
Enter the score for student number 4: 90
’Mike’:’F’, ’Minh’: ’A’,’Lan’:’A’,’Josh’:’A’
The number of students in Grade A is: 3
The number of students in Grade B is: 0
The number of students in Grade C is: 0
The number of students in Grade F is: 1
The output needs to be formatted exactly as it is shown in the example; otherwise, up to 5 pts will be
deducted.

Midterm - Fall 2024 Page 4


Problem 3 (40-pts) Functions
Part 3(a) (20pts): Write a function odds_sum(L) that takes 1 input as a list L. The function computes the
sum s of all the elements in the list L that are odd. For example, if L = [1,3,4,5], the function should
return 9 since 9 = 1 + 3 + 5. Assume L is a non-empty list of integers.

Testing code Expected output


print(odds_sum([1,3,4,5])) 9
print(odds_sum([-2,0,2,4,6,8])) 0
print(odds_sum([1,-3,3,7])) 8

Part 3(b) (20pts): The Fibonacci Sequence is a series of integer numbers. The next number is found by
adding up the two numbers before it. The first two numbers are 0 and 1. For example: 0, 1, 1, 2, 3, 5,
8, 13. The next number in this series above is 8+13 = 21. Write a function named Fibonacci() that takes
an integer input n. The function computes the nth Fibonacci number in the sequence above.
Hint: The number swapping trick when we learn about tuple can be useful.

Testing code Expected output


print(Fibonacci(15)) 377
print(Fibonacci(20)) 4181
print(Fibonacci(3)) 1
print(Fibonacci(25)) 46368

Midterm - Fall 2024 Page 5

You might also like