0

I am just getting into Python and I am a newb to say the very least. I am playing around in PyCharm and I am trying to put together something basic for Employee data entry.

I'm sure you can see the gist in my script. Anyway, first I have tried for a bit to figure away to get it to spit out Salary, Bonus and Annual as currency but can't. You know $60,000 instead of 60000.

Also, I wanted it to give a bi-weekly pay schedule if you entered in the date of the first paycheck.

I'm trying to brain storm.

name = input('Enter Employee Name: ')
# This should be an integer that represents the age of an employee at GPC
try:
    age = int(input('Enter Employee Age: '))
except:
    print('Please enter a whole number')
    exit()
job = input('Enter Employee Job: ')
# This should be an integer that represents the salary of the employee at 
GPC
try:
    salary = int(input('Enter Employee Salary to the Nearest Dollar: '))
except:
    print('Please enter only numbers without foreign characters')
    exit()
salary_bonus = int(input('Enter employee bonus percentage '))/100
annual_income = (salary * salary_bonus) + salary
import datetime
now = datetime.datetime.now() # Current Year
u = datetime.datetime.strptime('2016-12-30','%Y-%m-%d')
d = datetime.timedelta(weeks=2)
t = u + d

# Data Output

print('Employee: ', name)
print('Age: ', age)
print('Job Title: ', job)
print('Annual Salary: ', round(salary,2))
print('Biweekly Paycheck: ', round(salary / 26, 2))
print('Bonus for', now.year, ': ', round(salary * salary_bonus, 2))
print('Actual Annual Income: ', round(annual_income, 2))

print('Your pay schedule will be:')
print(t)
print(t+d)
Sam Russo
  • 145
  • 1
  • 3
  • 18
  • Possible duplicate of [Converting Float to Dollars and Cents](https://stackoverflow.com/questions/21208376/converting-float-to-dollars-and-cents) – Krupip Jun 20 '17 at 14:16
  • I tried that, and couldn't get it to work. So asking guidance with my script since I can't see why it doesn't work. – Sam Russo Jun 20 '17 at 14:51
  • what do you mean you couldn't get it to work? Its one line... `'${:,.2f}'.format(1234.5)`. just replace 1234.5 with your number, that is it. Its a format string, basically any string with {} inside can be used as a format. If you need further explanation of *why* that works, go to the link I provided. – Krupip Jun 20 '17 at 14:54

1 Answers1

0

You can use local.currency

import locale
locale.setlocale( locale.LC_ALL, '' )
print('Actual Annual Income: ', locale.currency(round(annual_income, 2), grouping=True))

locale.currency(val, symbol=True, grouping=False, international=False)

Formats a number val according to the current LC_MONETARY settings.

The returned string includes the currency symbol if symbol is true, which is the default. If grouping is true (which is not the default), grouping is done with the value. If international is true (which is not the default), the international currency symbol is used.

Note that this function will not work with the ‘C’ locale, so you have to set a locale via setlocale() first.

Ref : Python Documents: Internationalization services

P.S: For bi-weekly pay schedule, see Generating recurring dates using python?

RaminNietzsche
  • 2,683
  • 1
  • 20
  • 34