我正在尝试制作一个程序,您可以输入工作名称,类别和薪水,并且试图将输入的工作名称,类别和薪水写到文件中以存储数据,但是这样做有问题。
class Job(object):
def __init__(self, jobName = '', jobCategory = '', jobPay = ''):
self.jobName = jobName
self.jobCategory = jobCategory
self.jobPay = jobPay
def getName(self):
self.jobName = input("What is the Job Title: ")
def getCategory(self):
self.jobCategory = input("What is the Job Category: ")
def getPay(self):
self.jobPay = input("What is the Job Pay: ")
def displayJob(self):
print("Job: " + self.jobName)
print("Job Category: " + self.jobCategory)
print("Job Pay: " + self.jobPay)
print()
def Main():
global NewJob
NewJob = Job()
NewJob.getName()
NewJob.getCategory()
NewJob.getPay()
print()
NewJob.displayJob()
myFile = open('newFile.txt', 'w')
myFile.write(NewJob.displayJob())
myFile.close()
Main()
猛跑小猪
守着星空守着你
相关分类