Midterm Exam
This exam will test you on all competencies that we have covered so far. Make sure that you follow all directions explicitly for maximum points. Failing to follow directions will result in deductions. If you are not clear on a concept, you should ask me. This will take some time, so don’t start at the last minute!
Scenario:
You are running computer inventory in your small department. For this inventory, you need to collect 4 pieces of information for each computer and automatically generate a 5th
piece of information. There are 4 computers in the department.
Requirements:
1. Create a module named inventory.py. In this module:
a. Create a function named printHeader() that prints out a header that looks like this when called from the main() method.
b. Create a main() method that does this:
i. For each computer, prompt the user for this information:
1. Hostname is the name of the computer. (must be 8 characters or shorter, and must be printed out in all capitals).
a. If the user uses LESS than 8 characters:
i. While the length of the hostname is less than 8, you should loop and add the number 1 as a suffix until the length is 8 characters. Example: hostname is art. Printout should be ART11111.
b. If the user uses more than 8 characters, then you must truncate the hostname to just the first 8 characters entered. For example: user enters accountingpc. It should print out as ACCOUNTP. Hint: We haven’t covered this in class, so here is the code for accomplishing of grabbing the first 8 letters of the name:
2. Username is the computer username of the person that logs on to the pc. Usernames should be formatted identically as hostnames: Truncate to 8 if more than 8 characters, Pad to 8 if less than 8 characters. Convert usernames to uppercase.
3. Windows Version relates to the version of Windows. Prompt the user to enter the NUMBER of Windows. Acceptable values are 7, 8, or 10. If the user doesn’t enter 7, 8, or 10, then just assume that the value of Windows is 10. Pre-pend the user’s entry with the string “Windows “. Example: The user enters 8, so the string should be stored as “Windows 8”. The user enters 22, so the string should be stored as “Windows 10”.
4. Enter the GB of RAM that the computer holds. Note that the value must be an integer between 16 and 64. Keep prompting the user to enter a valid number between 16 and 64 in case they don’t do so.
2. Create a new module named generatetag.py.
i. Define a function named genTag that accepts 3 parameters: host, username, and ram).
1. The function should create an 8-digit asset tag composed of the first 2 letters of the hostname, first 2 letters of the username, the value of the ram, and a random integer between 10 and 99. Asset tags must all be uppercase.
a. Example: you pass hostname = ACCOUNTI, username = jsmith11, and ram = 32. Say you generate 34 as a random number. Then the asset tag is ACJS3234.
b. Return the value of the asset tag back to the calling method when called.
3. Back in Inventory.py:
a. Call genTag() and return the asset tag back to the appropriate asset variable.
b. Gather the information for the other 3 computers using the same code you just used, but use different variable names so as not to overwrite your variable values. The information gathering should look something like this:
c. Call printHeader()
d. Print out to the console the value of the each computer’s hostname, username, windows version, RAM, and Asset tag (which you generate by passing the values that you just collected on to the genTag() function).
e. Don’t forget to import the genTag() function from the generateTag.py file.
The final printout should look something like this: