我刚刚进入Python,我是一个新手说至少。我在PyCharm玩耍,我正在尝试为员工数据输入添加一些基本信息。转换为货币和打印双周计划
我相信你可以看到我的脚本中的要点。无论如何,首先我已经尝试了一些想法,让它能够将薪水,奖金和年度作为货币吐出,但不能。你知道60000美元,而不是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)
[转换浮动,以美元和美分(可能的重复https://stackoverflow.com/questions/21208376/converting -float-to-dollars-and-cents) – snb
我试过了,并且无法让它正常工作。所以问我的脚本指导,因为我不明白为什么它不起作用。 –
你是什么意思,你不能得到它的工作?它的一行......''$ {:,。2f}'。格式(1234.5)'。只需用你的号码代替1234.5,就是这样。它的格式字符串,基本上任何带{}的字符串都可以用作格式。如果您需要进一步解释* why *的作用,请转到我提供的链接。 – snb