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 8810317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:05:46+00:00 2026-06-14T03:05:46+00:00

Im learning python and am currently trying to pass values from input to the

  • 0

Im learning python and am currently trying to pass values from input to the args for a module I wrote but I have no idea how to start.

Can someone give me some advice?

This is the module im calling

#!/usr/bin/python

class Employee:
    'Practice class'
    empCount = 0

    def __init__(self, salary):
            self.salary = salary
            Employee.empCount += 1
    def displayCount(self):
            print "Total Employees %d" % Employee.empCount

    def displayEmployee(self):
            print "Salary: ", self.salary


class Att(Employee):
    'Defines attributes for Employees'
    def __init__(self, Age, Name, Sex):
            self.Age = Age
            self.Name = Name
            self.Sex = Sex

    def display(self):
            print "Name: ", self.Name + "\nAge: ", self.Age,  "\nSex: ", self.Sex

This is the code im using to call and pass the values to the args in the above module

#!/usr/bin/python

import Employee

def Collection1():
    while True:
            Employee.Age = int(raw_input("How old are you? "))
            if Employee.Age == str(Employee.Age):

                    print "You entered " + Employee.Age + " Please enter a number"
            elif Employee.Age  > 10:
                    break
            elif Employee.Age > 100:
                    print "Please enter a sensible age"
            else:
                    print "Please enter an age greater than 10"
    return str(Employee.Age)

def Collection2():
    Employee.Name = raw_input("What is your name? ")
    return Employee.Name


def Collection3():
    while True:
            Employee.Sex = str(raw_input("Are you a man or a woman? "))
            if Employee.Sex == "man":
                    Employee.Sex = "man"
                    return Employee.Sex
                    break
            elif Employee.Sex == "woman":
                    Employee.Sex = "woman"
                    return Employee.Sex
                    break
            else:
                    print "Please enter man or woman "
Attributes = Employee.Employee()

Collection1()
Collection2()
Collection3()


Attributes.displayEmployee()

Im guessing I need to take the input from the user and place it in the variables of the class. I tried that but im guessing im doing everything wrong??

  • 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-06-14T03:05:47+00:00Added an answer on June 14, 2026 at 3:05 am

    Employee.Age = int(raw_input("How old are you? "))
    There’s no use to setting a variable in the module instead of using a local variable, and setting whatever you need to set outside the Collection1() function. Note that you are not setting the employee (object) atributes’, but the module’s – this is probably not what you want. Also, functions, by convention, should be named with initial lowercase.

    Your inheritance model is a bit strange. Why are the employee attributes in a different (sub) class? Generally, the attributes go into the main class constructor. If you really want to use a separate class for the attributes, you shouldn’t use a subclass at all in this case.

    EDIT
    Here’s what I think you meant to do:

    #!/usr/bin/python
    
    class Employee:
        def __init__(self, salary, age, name, sex):
                self.salary =   salary
                self.age=       age
                self.name=      name
                self.sex=       sex
                #Employee.empCount += 1 #don't do this. you should count instances OUTSIDE
    
        def __str__(self):
                return "Employee<Name: {0}, Age: {1}, Sex: {2}, Salary: {3}>".format( self.name, self.age, self.sex, self.salary)
    
    
    
    def getAge():
        while True:
            try:
                s=raw_input("How old are you? ")
                age = int(s)
                if age > 100:
                    print "Please enter a sensible age"
                elif age<=10:
                    print "Please enter an age greater than 10"
                else:
                    return age
            except ValueError:
                print "You entered " + s + " Please enter a number"
    
    def getName():
        return raw_input("What is your name? ")
    
    
    def getSex():
        while True:
            sex = str(raw_input("Are you a man or a woman? "))
            if not sex in ("man", "woman"):
                print "Please enter man or woman "
            else:
                return sex
    
    
    
    age= getAge()
    name= getName()
    sex= getSex()
    salary=100000
    
    employee = Employee(salary, age, name, sex)
    print employee
    

    if you want the Employee in a different file (module), just put it there and from your main code run from Employee import Employee (the first is the module, the second is the class).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently learning on how to use the Python optparse module. I'm trying the
I am currently learning Python from MIT OCW courses ? Anyone who have used
I'm currently learning Python and I'm trying to make a small scraper but I'm
I'm currently learning python and trying to do exercises at pyschools (if anyone knows
I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one
im currently learning python (in the very begining), so I still have some doubts
I have just started learning python version 3 and trying to create a file
learning python currently and having a bit of a problem. I'm trying to take
I'm currently trying to wrap my head around learning Python and I've come to
I just started learning C++(coming from Java & Python) and am trying to learn

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.