def main():
print("this program creates a file of usernames from a ")
print("files of names ")
# get the file names
infilename = input("what files are the name in")
outfilename = input("what file should the usernames go in")
# open the files
infile = open(infilename,'r')
outfile = open(outfilename,'w')
# process each line of the input file
for line in infile.readlines():
# get the first and last names from line
first, last = line.split()
# create the username
uname = line.lower(first[0]+last[:7])
# write it to the output file
outfile.write(uname+'\n')
# close both files
infile.close()
outfile.close()
print("usernames have been written to : ", outfilename)
main()
파일에서 이름과 성을 묶어서 사용자 이름을 인쇄하는 프로그램을 작성하려고합니다. 이름과 나머지 성. 예 : alex
doug
은 adoug
입니다.lower() fuction이 인수를 취하지 않음
파이썬 인터프리터는 uname = line.lower(first[0]+last[:7])
에 오류를 표시합니다.
TypeError lower() takes no arguments (1 given)
있는 방법이 오류 주위에 있는가 또는 그것을 할 수있는 다른 방법은 무엇입니까?
line.lower (처음 [0] + 마지막 [: 7])의'line'은 실제로/do를 의미합니까? –
나는 첫 번째 이름에서 첫 번째 문자를 가져 와서 색인 7까지 성을 얻고 싶습니다. 그래서 이름의 첫 번째 이름이 4이고 마지막 이름이 chan이면 결과는 fchan이됩니다 –
예,하지만 그게 무슨 뜻인지 알 수 있습니다. 'first'와'last'를 사용하여,'line' 변수를 사용하는 것과는 다릅니다. 왜 그것이'line.lower (첫 번째 [0] + 마지막 [: 7]) '명령의 일부입니까? –