实际上有一种方法可以存储n个输入的每个不同输入,然后以正确的顺序显示所有这些输入,例如:
用户输入记录编号,姓名,员工类型,为n个用户工作的天数
在n个用户之后,它会一次显示以下所有:
记录编号:1
员工姓名:Alexander
员工类型:C
工作天数:5
收费(RM):2500.00
记录编号:2
员工姓名:贝拉
员工类型:V
工作天数:10
收费(RM):1000.00
记录编号:3
员工姓名:Tom
员工类型:S
工作天数:20
收费(RM):5000.00
或者只能逐个显示?这是我目前的代码
print("{0:^15s}{1:^25s}".format("Employee Type", "Employee Rate (per day)"))
print("{0:^15s}{1:>15s}".format("C", "RM 500.00"))
print("{0:^15s}{1:>15s}".format("S", "RM 250.00"))
print("{0:^15s}{1:>15s}".format("V", "RM 100.00"))
print()
numEmployee = 1
confirmation = 0
while confirmation != "Y":
numEmployee = input("Enter The Number Of Employees To Be Keyed In: ")
while numEmployee == str():
print("No Input Has Been Detected. Please Input Number Of Employee(s) In An Integer")
numEmployee = input("Enter The Number Of Employees To Be Keyed In: ")
while eval(numEmployee) <= 0:
print("Please Enter A Valid Number Of Employees")
numEmployee = input("Enter The Number Of Employees To Be Keyed In: ")
confirmation = input("Are You Sure You The Number Of Employee Is Correct? Enter Y to Continue or any other key to reenter The Correct Number:")
confirmation = confirmation.upper()
print()
numEmployee = eval(numEmployee)
#for recordNum in range (1, numEmployee + 1):
recordNum = 1
finalTotalC = 0
finalTotalS = 0
finalTotalV = 0
while recordNum <= numEmployee:
print("Record Number: ", recordNum)
recordNum = recordNum + 1
name = input("Employee Name: ")
while name == str():
print("Please Enter A Name")
name = input("Employee Name: ")
employeeType = input("Employee Type: ")
employeeType = employeeType.upper()
while employeeType == str():
print("No Input Has Been Detected. Please Input An Employee Type")
employeeType = input("Employee Type: ")
employeeType = employeeType.upper()
while employeeType != "C" and employeeType != "S" and employeeType != "V":
print("Employee Type Is Invalid. Please Enter C,S or V Only")
employeeType = input("Employee Type: ")
employeeType = employeeType.upper()
daysWorked = input("Days Worked: ")
while daysWorked == str():
print("No Input Has Been Detected. Please Input Number Of Days Worked In That Month")
daysWorked = input("Days Worked: ")
while eval(daysWorked) < 0 or eval(daysWorked) > 31:
print("Please Enter The Number Of Days In A Range Of 0 until 31 Only")
daysWorked = input("Days Worked: ")
daysWorked = eval(daysWorked)
if employeeType == "C":
EMPLOYEERATE = 500.00
print("Pay (RM): ", format(daysWorked*EMPLOYEERATE, ",.2f"))
totalC = daysWorked*EMPLOYEERATE
finalTotalC = finalTotalC + totalC
print()
if employeeType == "S":
EMPLOYEERATE = 250.00
print("Pay (RM): ", format(daysWorked*EMPLOYEERATE, ",.2f"))
totalS = daysWorked*EMPLOYEERATE
finalTotalS = finalTotalS + totalS
print()
if employeeType == "V":
EMPLOYEERATE = 100.00
print("Pay (RM): ", format(daysWorked*EMPLOYEERATE, ",.2f"))
totalV = daysWorked*EMPLOYEERATE
finalTotalV = finalTotalV + totalV
print()
答案 0 :(得分:0)
您需要在接收数据时将数据存储在某处。我建议一个列表(https://docs.python.org/2/tutorial/datastructures.html#more-on-lists)的dicts(https://docs.python.org/2/tutorial/datastructures.html#dictionaries)可能适合您的情况。然后,您可以在完成后迭代列表(为了打印)。