我修復了間距問題,並糾正了其他錯誤。現在它正在做我想做的事情,但是我選擇了選擇2,它將打印出員工4次的記錄。如果我輸入另一個員工,它只會打印第二個員工,而不是第一個員工。循環中的Python錯誤
class EmployeeClass:
def Employee(name, lastName, age, salary):
name = name
lastName = lastName
age = age
salary = salary
def displayEmployee(x):
print("Name: " + name + ", " + lastName)
print("Age: " + age)
print("Salary: " + salary)
EmployeeArray = []
Continue = True
print ("Employee Information V2.0")
while Continue == True:
print ("Welcome to Employee Information")
print ("1: Add New Record")
print ("2: List Records")
print ("3: Quit")
choice = input()
if choice == "1":
name = input ("Enter First Name: ")
EmployeeArray.append(name)
if name == "":
Continue = False
print ("Goodbye!")
break
lastName = input ("Enter Last Name: ")
EmployeeArray.append(lastName)
age = input ("Enter Age: ")
EmployeeArray.append(age)
salary = input ("Enter Salary: ")
EmployeeArray.append(salary)
elif choice == "2":
for Employee in EmployeeArray:
EmployeeClass.displayEmployee(Employee)
Continue = False
elif choice == "3":
print ("Bye!")
break
else:
print ("Please choose a valid option")
print ("\n")
我從你的建議切換到Notepad ++。我更喜歡它。謝謝。 – NineTail 2012-08-14 15:46:51