这是我的代码
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import re
#read information
f = open ("/home/ibrahim/Desktop/Test.list")
text = f.read()
#show existing companys
for line in open('/home/ibrahim/Desktop/Test.list'):
company, founding_year, number_of_employee = line.split(',')
print "Company: %s" % company
#User chooses a company he wants to know more about
CompanyIndex = raw_input('\n<Choose a company you want to know more about.>\n\n<Insert a companyspecific-number and press "Enter" .>\n')
#Companyspecific information is getting revealed
if CompanyIndex == '1':
print #company1,founding_year1,number_of_employee2
elif CompanyIndex == '2':
print #company2,founding_year2,number_of_employee2
elif CompanyIndex == '3':
print #company3,founding_year3,number_of_employee3
else:
print 'Your input is not correct..'
我的目标是该程序的用户可以选择他想了解更多的特定公司,例如该公司成立的年份和员工人数示例:公司名称 = 厨师,公司成立年份 = 1965 和人数employees = 10 我不想打印超过公司名称的信息,因为未来的信息将不仅仅包含创始年份和员工人数;)看到这么多信息会很混乱^^现在我的问题是,我不知道如何保存收到的有关公司的信息以及如何在此块中打印这些信息:
if CompanyIndex == '1':
print #company1,founding_year1,number_of_employee2
elif CompanyIndex == '2':
print #company2,founding_year2,number_of_employee2
elif CompanyIndex == '3':
print #company3,founding_year3,number_of_employee3
else:
print 'Your input is not correct..'