Python Forum
class and objects beginning python 3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
class and objects beginning python 3
#1
I am totally lost. The assignment is mentioned below after the quotes.
This is all I can come up with:


#!/usr/local/bin/python3


class Student:
def __init__(self, name):
self.name = name
# self.address = address
# self.city = city
# self.state = state
# self.zip = zip
# self.gender = gender
# self.studentid = studentid
# self.gpa = gpa
def std1(self):
std1 = Student()
#std2 = Student()
#std3 = Student()
self.name = input("Enter: ")
return(self.name)

print(Student(std1.name))


I have been editing as I have been trying various troublshooting so it's a bit of a mess. any help will do.


"""""""
In this lab you will write an object specification into a program, and customize

its data fields. You will declare objects using the object specification, and assign values to its data fields.
You will also use an object as an input parameter in a function call, and as an
output parameter, too.
Requirements: Write a program that
(1) Creates an object specification with these eight data fields: name, address, city, state, zip, gender, student id, and gpa.
(2) Declare 3 uninitialized, individual student objects.
(3) Write a value-returning function to create a return a single student object. Design prompts for the user that takes input in the function for the eight data fields. Call the function three times -- once to initialize each student object.
(4) Write a function that does not return any value that outputs each student object. Call the function three times -- once for each student object.
Program I/O -- Input from the keyboard the personal information of 3 students, one student at a time. Output a summary for each of the 3 students that contains the personal information entered for each student.
Example -- Your program I/O should look something like this, with the user input in bold text and the program output in normal text (note: you do not have to make the user input in bold text, it is just shown here in bold to demonstrate what the user could type):
Enter for Student 1
name: Xio Chen
address: 123 Happy Street
city: Happytown
state: CA
zip: 12345
gender: female
student id: abc123
gpa: 4.0
Enter for Student 2
name: Carlos Ortega
address: 456 Happy Street
city: Gladtown
state: CA
zip: 54321
gender: male
student id: abc123
gpa: 4.0
...
etc,
Output for Student 1:
Name: Xio Chen
Address: 123 Happy Street
...
etc.
Output for Student 2:
Name: Carlos Ortega
Address: 456 Happy Street
...
etc.
Reply
#2
Please, put your code between python code tags. See how here.

Are you creating the objects inside the class definition?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
Requirements (1) and (2) are somewhat related. You want to define a class with those fields (1) but then create objects of that class where none of those fields have values (e.g., are "uninitialized").

You are on the right path with the class definition you have except the __init__ method (aka "constructor") takes an argument which means you can't create a Student object without initializing at least one field.

You might also want to approach this from steps 3 and 4 and write a function that prompts the user for Student information and then return a class object.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  beginning python help request (for loop) casey 3 2,714 Oct-26-2018, 07:26 PM
Last Post: casey
  Python Objects and functions jill1978 1 7,991 Oct-08-2018, 06:15 AM
Last Post: buran
  Beginning Payroll code help EmRandall 6 9,012 Sep-18-2018, 01:21 AM
Last Post: EmRandall

Forum Jump:

User Panel Messages

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