hello,
I just signed up to ask...How would I store the information from my code(see below) into a object? I'll be naming the object employees.
The code I have now executes this:(please tell me if there are any mistakes on the code I have so far)

1.Ask the user to enter payroll information for the company. Set up a loop that continues to ask for information until the user enters “DONE”. For each employee ask three questions:
name (first & last name together as a single response)
hours worked this week (only allow 1 through 60)
hourly wage (only allow 6.00 through 20.00)

***Now this is where I get confused on structure and so on:

2.Create an EMPLOYEE object that will store the name, hours worked, and hourly wage. After the 3 items of information have been entered for an employee, use a method of the EMPLOYEE object to print the name, hours worked, and hourly wage. Setup properties for the name, hourly wage, and hours worked. Create a method that will calculate the employee’s pay (as a private attribute). Create a property for the employee’s pay. Add to a list only the pay for each employee.
Weekly pay is calculated:
For (1-40 hours) it is hourly rate * hours worked
For (41-60 hours) it is (hours worked – 40) * (hourly rate * 1.5)
+ (hourly rate * 40)

***helping in code would be appreciated!

This is what I have for number one:

import sys

while True:
name=raw_input('Enter a name:')
if name == 'DONE':
break
hours=raw_input('Hours worked:')
if hours == 'DONE':
break
else:
while int(hours) > 60 or int(hours) < 1:
hours=raw_input('Hours worked:')
if hours == 'DONE':
sys.exit(0)
hwage=raw_input('Enter hourly wage:')
if hwage == 'DONE':
break
else:
while int(hwage) > 20 or int(hwage) < 5:
hwage=raw_input('Enter hourly wage:')
if hwage == 'DONE':
sys.exit(0)

for indentation: http://pastebin.com/zjtpVAyx

I appreciate your help.

Editors note:
Can't rescue your code, it's totally missing proper Python indentations

In the future, please use code tags with your code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help.

[code]
your Python code here
[/code]

Edited 3 Years Ago by diafol: fixed formatting

You can append your data to a list (or a dictionary of name:data_list pairs) and save it as a list or dictionary object with module pickle. Here is a typical example of pickle ...

# use module pickle to save/dump and load a dictionary object
# or just about any other intact object
# use binary file modes "wb" and "rb" to make it work with
# Python2 and Python3

import pickle

# create the test dictionary
before_d = {}
before_d[1]="Name 1"
before_d[2]="Name 2"
before_d[3]="Name 3"

# pickle dump the dictionary
fout = open("dict1.dat", "wb")
# default protocol is zero
# -1 gives highest prototcol and smallest data file size
pickle.dump(before_d, fout, protocol=0)
fout.close()

# pickle load the dictionary
fin = open("dict1.dat", "rb")
after_d = pickle.load(fin)
fin.close()

print(before_d)  # {1: 'Name 1', 2: 'Name 2', 3: 'Name 3'}
print(after_d)   # {1: 'Name 1', 2: 'Name 2', 3: 'Name 3'}

Edited 5 Years Ago by vegaseat: n/a

You can just code a while() instead of the if() and while().

hours = 0
while int(hours) > 60 or int(hours) < 1:
    hours=raw_input('Hours worked:')
    #
    # the following is poor syle; use if statement instead
    #if hours == 'DONE':
        #break
    #else
    #
    if hours.upper() != 'DONE':
        hwage = 0
        while int(hwage) > 20 or int(hwage) < 5:
            hwage=raw_input('Enter hourly wage:')
#
#etc. for the rest of the input

Edited 5 Years Ago by woooee: n/a

This question has already been answered. Start a new discussion instead.