我刚开始接触Python,至少可以说我是个新手。我正在使用PyCharm,并且正在尝试组合一些用于输入员工数据的基本内容。
我相信您可以看到我的脚本中的要点。不管怎么说,首先我试了一下,把工资、奖金和年薪都写成货币,但是不能,你知道是60,000美元,而不是60000美元。
此外,我希望它给出一个双周支付时间表,如果你输入了第一个工资支票的日期。
我在试着头脑风暴。
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)发布于 2017-06-20 22:15:20
您可以使用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)
根据当前LC_MONETARY设置格式化数字val。
如果symbol为true,则返回的字符串包括货币符号。如果grouping为true (这不是默认值),则使用该值进行分组。如果international为true (这不是默认值),则使用国际货币符号。
请注意,此函数不适用于‘C’语言环境,因此您必须首先通过setlocale()设置语言环境。
参考:Python Documents: Internationalization services
附注:有关每两周支付一次的时间表,请参阅Generating recurring dates using python?
https://stackoverflow.com/questions/44655125
复制相似问题