Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

5. 파이썬입출력

1. 사용자 키보드로 이름을 받아 “안녕하세요 OOO님” 이라고 출력하는 코드

=================================== RESTART: E:\test\test.py ==================================
이름: apple
안녕하세요 apple님
답(안)
a = input("이름: ")
b = "안녕하세요 {0}님".format(a)
print(b)

2. 구구단을 gugudan.txt 파일로 출력하는 코드

답(안)
file = open("gugudan.txt", 'w')

i = 2
while i <= 9 :
    j = 1    
    while j <= 9 :
        a = "{0} * {1} = {2}\n".format(i, j, i*j)        
        file.write(a)

        j += 1
    i += 1

file.close()

3. 구구단을 아래 그림처럼 엑셀에서 읽을 수 있는 gugudan.csv 파일로 출력하는 코드

답(안)
file = open("gugudan.txt", 'w')

i = 2
while i <= 9 :
    j = 1    
    while j <= 9 :
        a = "{0} * {1} = {2}\n".format(i, j, i*j)        
        file.write(a)

        j += 1
    i += 1

file.close()