【发布时间】:2018-03-09 05:06:17
【问题描述】:
打印询问用户姓名
name = input("what is your name ")
file_name = str(input("What do you want to name this .txt file\n> "))
if file_name[-4:] != ".txt":
file_name += ".txt"
问候他们
询问那里的姓名和员工姓名
print("Why hello",name,"now lets caculate that employee's next pay check")
def employees():
emplist = []
while True:
names = input('What is the name of the employee')
if names == 'done':
break
else:
emplist += [names]
print(emplist)
pay(emplist)
要求按小时计酬
def pay(emplist):
for person in emplist:
print("now i need hourly pay of",person,)
pay = float(input("> "))
询问他们的工作时间
print("now i need the hours worked by",person,)
hours = float(input("> "))
计算工资
做数学题
if hours > 40:
over = 1.50
overtimeR = over * pay
overtime = overtimeR * (hours-40)
hours += 40
else:
overtime = 0
让他们做出不同的反应
尚未完成
if overtime > 0:
hours2 = 40
totalpay = (pay * hours2) + overtime
pay_without_overtime = pay * hours2
else:
totalpay = (pay * hours) + overtime
person_2 = ""
person_2 += person
info = ("Employee: "+str(person_2)+"\nTotal Hours: "+str(hours))
with open(file_name, 'a+')as file_data_2:
file_data_2.append(info)
employees()
但它给了我错误
我该如何解决这个问题
AttributeError: '_io.TextIOWrapper' object has no attribute 'append'
【问题讨论】:
-
你没有
append到一个文件。你write给它。有关详细信息,请参阅docs.python.org/2/tutorial/…。
标签: python attributeerror