편집 기록

편집 기록
  • 프로필 알 수 없는 사용자님의 편집
    날짜2018.05.26

    파이썬에서 파일 입출력 하는 코드를 짜는 문제를 푸는 중인데 어디서 틀렸는지 모르겠어요 ㅠㅠ


    ![![![이미지][1]][1]][1]```python

    inputfile=open("ALE.txt","r")

    outputfile=open("ALE2.txt","w")

    list1=[]

    for line in inputfile:

    Team,Won,Lost=line.split(',')
    Won=int(Won)
    Lost=int(Lost)
    Percentage=round((Won)/(Won+Lost),3)
    list1.append([Percentage,Team,Won,Lost])
    

    list1.sort(reverse=True)

    print("Team\tWon\tLost\tPercentage")

    for i in range(len(list1)):

    outputfile.write("{0:<10},{1:<10},{2:<10},{3:<10}".format(list1[i][2],list[i][3],list[i][4],list[i][0]))
    

    inputfile.close() outputfile.close()

    
    ALE 안에 있는 자료는 다음과 같아요. 문제에선 Percentage를 내림차순으로 정렬해야한다 해서 `list.sort(reverse=True)`를 넣었어요.
    
    ``` 문제의 의도는 ALE안의 자료를 위에 있는 사진처럼 ALE2에 옮겨야 해요. ALE의 내용은 밑에 있는 것과 같은데 줄과 줄 사이에는 원래 공백이 없어요.
    
    Baltimore,93,69
    
    Boston,69,93
    
    New York,95,67
    
    Tampa Bay,90,72
    
    Toronto,73,89
    

    어느 부분에서 틀렸고 고쳐야 하는 방법도 알려주시면 정말 감사하겠습니다. ㅠㅠ

  • 프로필 유동욱님의 편집
    날짜2018.05.26

    파이썬에서 파일 입출력 하는 코드를 짜는 문제를 푸는 중인데 어디서 틀렸는지 모르겠어요 ㅠㅠ


    inputfile=open("ALE.txt","r")
    
    outputfile=open("ALE2.txt","w")
    
    list1=[]
    
    for line in inputfile:
    
        Team,Won,Lost=line.split(',')
        Won=int(Won)
        Lost=int(Lost)
        Percentage=round((Won)/(Won+Lost),3)
        list1.append([Percentage,Team,Won,Lost])
    
    list1.sort(reverse=True)
    
    print("Team\tWon\tLost\tPercentage")
    
    for i in range(len(list1)):
    
        outputfile.write("{0:<10},{1:<10},{2:<10},{3:<10}".format(list1[i][1],list[i][2],list[i][3],list[i][0]))
    inputfile.close()
    outputfile.close()
    

    ALE 안에 있는 자료는 다음과 같아요. 문제에선 Percentage를 내림차순으로 정렬해야한다 해서 list.sort(reverse=True)를 넣었어요.

    Baltimore,93,69
    Boston,69,93
    New York,95,67
    Tampa Bay,90,72
    Toronto,73,89
    

    어느 부분에서 틀렸는지 알려주시면 정말 감사하겠습니다. ㅠㅠ

  • 프로필 알 수 없는 사용자님의 편집
    날짜2018.05.26

    파이썬에서 파일 입출력 하는 코드를 짜는 문제를 푸는 중인데 어디서 틀렸는지 모르겠어요 ㅠㅠ


    inputfile=open("ALE.txt","r")

    outputfile=open("ALE2.txt","w")

    list1=[]

    for line in inputfile:

    Team,Won,Lost=line.split(',')
    Won=int(Won)
    Lost=int(Lost)
    Percentage=round((Won)/(Won+Lost),3)
    list1.append([Percentage,Team,Won,Lost])
    

    list1.sort(reverse=True)

    print("Team\tWon\tLost\tPercentage")

    for i in range(len(list1)):

    outputfile.write("{0:<10},{1:<10},{2:<10},{3:<10}".format(list1[i][1],list[i][2],list[i][3],list[i][0]))
    

    inputfile.close() outputfile.close()

    ALE 안에 있는 자료는 다음과 같아요. 문제에선 Percentage를 내림차순으로 정렬해야한다 해서 list.sort(reverse=True)를 넣었어요. Baltimore,93,69 Boston,69,93 New York,95,67 Tampa Bay,90,72 Toronto,73,89

    어느 부분에서 틀렸는지 알려주시면 정말 감사하겠습니다. ㅠㅠ