Practice exam 1
Instructions
-
The source code you submit must be entirely your work and must be written entirely during the class period. The use of any pre-existing code (other than that provided as part of the exam) is prohibited.
-
You must login using the username
student
(which does not have a password), not using your eid. -
You may only use a terminal/shell window, Thonny and a web browser. The only page you may load in the WWW browser is the course submission site.
-
Your code need not comply with the course style guidelines and need not include comments.
-
You must submit your code using Gradescope. Your code for each question must be submitted separately in a single .py file (appropriately named).
-
Your last submission is the one that will be graded. No limit will be placed on the number of submissions but, obviously, you must complete the exam during the class period and submissions take time.
-
Your answers must not contain items not covered in Chp 1-5 of the class textbook (if-then-else, loops, etc…).
Question #1: Standard Time Format(20 points)
Write a program named time.py
that prompts the user for integers representing some number of hours, minutes and seconds, and then prints out the corresponding amount of time in a standardized form where the number of minutes and seconds are both less than 60. See below for examples of executing the program. The formatting for your output must exactly match these examples.
Hours: 0
Minutes: 5
Seconds: 120
0 hour(s), 7 minute(s) and 0 second(s).
>>> %Run time.py
Hours: 1
Minutes: 61
Seconds: 121
2 hour(s), 3 minute(s) and 1 second(s).
Hints: First convert the provided amount of time into the total number of seconds, then use integer division (//) and the mod operator (%) to break the total number of seconds into hours, minutes and seconds.
Question #2: Student Accounts(30 points)
For this question you will write some utility functions that will be used for setting up student accounts in the new JMU student management system. Create a python file named student_util.py
and implement the following two functions:
generate_email
: This function must have a single parameter representing the last name of a student. It must return an email address generated from the student’s name. Email addresses are constructed by combining the first, middle and last letters of the name with the string@dukes.jmu.edu
. For names with an even number of letters, the function must use the second of the two middle letters. For example:- The name
"Smith"
would result in the address"Sih@dukes.jmu.edu"
. - The name
"Wong"
would result in the address"Wng@dukes.jmu.edu"
.
- The name
student_record
: This function must take three parameters representing the first, middle and last name of the student, in that order. It must return a list containing three elements:- The value at index 0 must be an integer student id that is unique for each student. The first time this function is called, the student ID must be 1000, and each subsequent call must the id must be increased by 1.
- The value at index 1 must be a single string containing the student’s full name in the format “Last, First Middle”.
- The value at index 2 must be the student’s email addressed as formatted by the
generate_email
function. (Do not repeat the code for generating an email address! For full credit, yourstudent_record
function must include a call togenerate_email
.)
Here is an example of the expected behavior of the student_record
function: