03 Prepare : Checkpoint A
Objective
Demonstrate basic classes in Python.
Instructions
After completing (or while completing) the preparation material for this week, complete the following exercise.
Write a Python 3 program according to the following:
Create a class for a Student, that contains a first name, a last name, and an id.
Create an
__init__function in your class that initializes the first name, last name, and id to "", "", and 0, respectively.Create a regular function (not a member function just yet) called
prompt_studentthat creates a new student object, then prompts the user for a first name, last name, and id. The function should assign these to the appropriate properties of the object and return it.Create a regular function (not a member function) called
display_studentthat accepts a student object, and displays its information in the following format: "id - FirstName LastName".
Then, create a main function that does the following:
Calls the prompt_student function and saves the returned value in a variable called "user".
Pass the user object to the display_student function to be displayed.
Sample Output
The following is an example of output for this program:
Please enter your first name: Ashley
Please enter your last name: Smith
Please enter your id number: 12512
Your information:
12512 - Ashley Smith
Automatic Grading Script (TestBed)
This assignment is pass/fail. In order to receive credit, it must pass the auto-grading test script (TestBed). You can run this script as many times as you like while you are working on the assignment. The same test script will be run by the instructor for credit, so you should not be surprised at the result.
In addition, because the point of this exercise is to help you practice the use of classes. You must use classes to receive credit for this assignment.
To run the test script, log into the CS Department Linux system and run the testBed command, providing the class and test script to run as well as the Python program to use, for example:
testBed cs241/check03a check03a.py
Submission
Submit your program by logging into the CS Department Linux system, and running the submit command with your filename, for example:
submit check03a.py
You should then select the appropriate course (CS 241), instructor, and assignment (check03a) from the list.