我剛剛進入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