Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7588203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:51:55+00:00 2026-05-30T19:51:55+00:00

I have no idea what is wrong! This is a very simple program and

  • 0

I have no idea what is wrong! This is a very simple program and I have done a lot head banging! Please someone enlighten me!

This a lab problem from the CSE 111 – Programming Language II course. They teach Java at the university and the code I wrote in Java works fine.

I just have to create a Student class with some fields to hold the basic information about a student with methods to get and set the attributes. Then create an instance of that class and tryout the methods.
But every time I run this program the following error occurs:

TypeError: set_name() takes exactly 1 positional argument (2 given)

Here is the code I wrote.

class Student:
    '''Student class'''

    name = None
    id = 0
    address = None
    cgpa = None

    def get_name():
        return name

    def set_name(n):
        name = n

    def get_id():
        return id

    def set_id(i):
        id = i

    def get_address():
        return address

    def set_address(a):
        address = a

    def get_cgpa():
        return cgpa

    def set_cgpa(c):
        cgpa = c


#An object of Student class
jack = Student()

jack.set_name('jacky')
print(jack.get_name())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:51:56+00:00Added an answer on May 30, 2026 at 7:51 pm

    You’re not accepting a reference to your instance as the first argument to that method, i.e. your set_name() should be written:

    def set_name(self, n):
        self.name = n
    

    This is somewhat different from other languages where there is a built-in keyword (such as this) that refers to the current object. Python passes that reference explicitly, as an argument to the method.

    All your other methods must be modified similarly.

    Note that just setting name = n sets a local variable name which goes away when the method ends; it does not set anything on the instance. You have to explicitly set self.name if you want an instance attribute.

    Also, and this is a matter of style, but you do not usually write set and get methods in Python. It is normal practice to set and get attributes directly. If you want to do validation of values, use a property instead. So basically, none of your methods are actually necessary in good style.

    However, you don’t have an __init__() method. Usually you would pass the desired attributes of the instance when instantiating the class and save these on the instance.

    class Student:
    
        def __init__(self, name, id, address, cgpa):
            self.name    = name
            self.id      = id
            self.address = address
            self.cgpa    = cgpa
    
    herman = Student("Herman Munster", 12345, "1313 Mockingbird Lane", 4.0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

maybe a very simple question, however I have no idea what I do wrong,
Does anyone have any idea what is wrong with this create statement for mysql?
This is probably a very simple one to be answered... I have a piece
I have this very simple form: <form id=header_search><input type=text value=search></form> and this is my
Hey! Maybe I am getting the idea of a subclass wrong, but I have
I have this idea for a free backup application. The largest problem I need
I have an idea for a simple application which will monitor a group of
I have an idea for how to solve this problem, but I wanted to
I'm just trying to preform a very simple jQuery action. I have two components:
**Despite how long this looks, I know it is very simple, I just added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.