【发布时间】:2013-08-07 08:06:09
【问题描述】:
Python 3 程序允许人们从员工姓名列表中进行选择。 文本文件中保存的数据如下所示:('larry', 3, 100) (作为人名、工作周数和付款)
我需要一种将文本文件的每个部分分配给新变量的方法, 这样用户就可以输入新的周数,程序会计算新的付款。
以下是我的代码,并尝试弄清楚。
import os
choices = [f for f in os.listdir(os.curdir) if f.endswith(".txt")]
print (choices)
emp_choice = input("choose an employee:")
file = open(emp_choice + ".txt")
data = file.readlines()
name = data[0]
weeks_worked = data[1]
weekly_payment= data[2]
new_weeks = int(input ("Enter new number of weeks"))
new_payment = new_weeks * weekly_payment
print (name + "will now be paid" + str(new_payment))
【问题讨论】:
标签: file variables python-3.x