2016-11-17 5 views
-2

대부분의 코드가 수정되었지만 내가 가지고있는 유일한 문제는 텍스트가 표시되지 않는다는 것입니다. 나는 골퍼 이름과 점수를 입력해야하지만 프로그램을 실행할 때 아무 것도 나타나지 않습니다.내 코드를 실행해도 아무 것도 보이지 않습니다.

def main(): 
    inGolf = open('golfers.txt', 'r') 
    names = [] 
    scores = [] 
    for line in inGolf: 
     line_list = line.split(",") 
     names.append(line_list[0]) 
     scores.append(line_list[1]) 

    for i in range(len(names)): 
     print ("{0:20}{1:10}".format(names[i], scores[i])) 
    inGolf.close() 

def w(numPlayers): 
    counter = 0 
    outGolf = open('playerData.txt', 'w') 
    while counter < numPlayers: 
     name = raw_input("Please enter the player's name:") 
     outGolf.write(name + ",") 
     score = input("Please enter that player's score:") 
     outGolf.write(str(score) + "\n") 
     counter = counter + 1 
    outGolf.close() 

main() 
+1

당신이 전화하지가 전체의 기능이있다, 어쩌면 조사를? – jonrsharpe

+0

'main()'의 첫 번째'for' 루프를 입력했는지 확인하기 위해 인쇄 문구를 추가하십시오. – mitoRibo

+1

그리고 그 동안 파일 이름이 다른 이유를 알아낼 수 있습니까? –

답변

0

나는 약간에게 here를 시도하는이 스크립트를 수정하고 실제로 일 : 그것은 플레이어 번호 플레이어의 이름과 점수를 묻는

  1. .
  2. 플레이어 파일을 저장합니다.
  3. 플레이어 파일을 읽고 점수 결과를 표시합니다.

나는 Python3에 관해서는 inputraw_input을 변경했고, 사용자 입력에 의해 플레이어의 숫자를 통과하는 w 기능이라고 :

def main(): 

    num_players = input("How many players?") 
    w(int(num_players)) 
    inGolf = open('golfers.txt', 'r') 
    names = [] 
    scores = [] 
    for line in inGolf: 
     line_list = line.split(",") 
     names.append(line_list[0]) 
     scores.append(line_list[1]) 

    for i in range(len(names)): 
     print ("{0:20}{1:10}".format(names[i], scores[i])) 
    inGolf.close() 


def w(numPlayers): 
    counter = 0 
    outGolf = open('golfers.txt', 'w') 
    while counter < numPlayers: 
     name = input("Please enter the player's name:") 
     outGolf.write(name + ",") 
     score = input("Please enter that player's score:") 
     outGolf.write(str(score) + "\n") 
     counter = counter + 1 
    outGolf.close() 

main() 
+0

감사합니다. 너 너무 많이! 또한 메신저 그냥 "어떻게 골퍼의 수를 삽입" – vtecjustkickedinyo

관련 문제