Python Forum
Please Help with Python Program!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please Help with Python Program!
#1
I am in Python 2 currently running Python 2.7, and I am in desperate need of some help making a quick program that is due Sunday 9/2, any and all help would be greatly appreciated.


We're going to write a program that manages the email address of our contacts. Your program must contain a class named contact that has 3 attributes (instance variables): last name, first name, and email. Your class should also have a method to return the name and email address for printing when requested. You may add other methods to the class if you like.

Each contact should use a single instance of your contact class. You should use either a list or a dictionary to act as a container of the contact instances.

Also, the program should have a menu that allows the user to interact with your collection of contacts: displaying contacts or adding new contacts as long as the user wishes, then saying goodbye when finished. The menu should offer these options.

Program Options.
1.) Display all contacts
2.) Create new contact
3.) Exit
option = raw_input("Enter 1, 2, or 3: ")

There are several examples of this kind of menu program scattered throughout the lecture notes for the first several weeks of the semester. The example most relevant to this assignment comes as the end of the notes on Classes.

For full credit.

use a python class to represent the contact info and at least one method to print that info.
collect each new contact instance in a list or dictionary.
please format printed output.


Here is a possible print-out, where we display some pre-existing contacts, add a new contact, then re-display the list to see that our contact has been added. Again, you do not need to save before exiting.
Reply
#2
we don't write code. We will help with the code that you write.
Show your code, along with any error tracebacks.
Reply
#3
We gladly help, but first you need to show the code you have done so far and ask specific questions about errors you get, or explain the undesired result you get vs. the desired one, etc.
Noone here will do the work for you though.
Reply
#4
(Sep-01-2018, 11:40 PM)j.crater Wrote: We gladly help, but first you need to show the code you have done so far and ask specific questions about errors you get, or explain the undesired result you get vs. the desired one, etc. Noone here will do the work for you though.
I understand, my problem is that I don't know where to start. So far I have;

class Contact(object):

I really don't know where to go from here. I am unsure how to define the 3 attributes of the contact which are first name last name and email.
Reply
#5
For start, check our tutorial on Classes basics
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
class Contact(object):

     def __init__(self, fname, lname, email):
          self.fname = fname
          self.lname = lname
          self.email = email

     def getFname(self):
          return self.fname
  
     def getLname(self):
          return self.lname

     def getEmail(self):
          return self.email
This is what I have so far, it says that I am supposed to use a list to act as a container for each instance of the class, how do I setup a list to contain each instance of the class?
Reply
#7
I'm not sure that your assignment wants methods for each property. Actually these methods does not make sense and also your assignment if it requires this. When I say they don't make sense I mean their syntax is correct, but you don't need them. You can access properties of a class by simply refer to them, e.g.

class Contact(object):
     def __init__(self, fname, lname, email):
          self.fname = fname
          self.lname = lname
          self.email = email

contact = Contact('John', 'Doe', '[email protected]')
print(contact.email)
I think they want one method that returns both name and e-mail address.

As to the list - you need to have list that will hold all instances of Contact class that you create. Note that you need to provide menu and an option to create contact. Try to do something yourself and then post the code here.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020