我是编程新手,只是学习如何使用类。我选择用于课程的第一项任务是建立一个数据库"一些公司的员工。
我的问题是我想创建一个input()函数/变量来决定我想从哪个员工获取信息。
我的代码如下所示:
class Employee:
def __init__(self, name, job, salary):
self.name = name
self.job = job
self.salary = salary
def print_job(self):
print(self.job)
def print_salary(self):
print(self.salary)
def print_all(self, info):
if info == "job":
print(self.job)
elif info == "salary":
print(self.salary)
elif info == "all":
print("Name: " + self.name)
print("Job: " + self.job)
print("Salary: " + self.salary)
August = Employee("A.V. Fornitz Lyngstrand", "CEO", "50%" )
Rasmus = Employee("Rasmus F. Preisler", "Co. Founder", "50%")
Helle = Employee("Helle Rasmussen", "Investor", "0%")
emp = input("Who are you searching for? ")
print("Searching for", emp + "...")
info = input("What do you want to know?")
August.print_all(info)
我做了一个名为" emp"然后我试着说
emp.print_all(info)
但它没有打印任何东西。
提前致谢