Example of Python code (C code to Python code)

Alex cut_me_out at hotmail.com
Tue Jun 6 23:54:28 EDT 2000


def get_float (prompt):
    while 1:
        number = raw_input (prompt)
        try:
            number = float (number)
        except ValueError:
            print 'Please enter a numerical value (just ' \
                  'digits and maybe a period.)'
            continue
        break
    return prompt

hours = get_float ('Please enter the hours worked per week? ')
rate  = get_float ('Please enter the rate of pay? ')

regular_hours = 40

if hours > regular_hours:
    overtime = hours - regular_hours
    overtime = overtime * rate * 1.5
else:
    overtime = 0

gross = (hours - overtime) * rate + overtime

min_salary = 300

if gross > min_salary:
    tax = (gross - min_salary) * .23
else:
    tax = 0

net = gross - tax

print 'Gross: %f, Net: %f' % (gross, net)





More information about the Python-list mailing list