ch10
문제 1
lib.py
def read():
f=open("input.txt", "r")
for _ in range(3):
str = f.readline().rstrip()
print(str)
f.close()
main.py
import lib
def main():
lib.read()
if __name__ == "__main__":
main()

문제 2
lib.py
def read():
f=open("input.txt", "r")
res = ""
for str in f:
str = str.rstrip()
words = str.split()
for word in words:
if(len(res) < len(word)):
res = word
f.close()
return res
main.py
import lib
def main():
res = lib.read()
print(f"가장 긴 단어는 {res} 입니다.")
if __name__ == "__main__":
main()

문제 3
lib.py
def read(fileName, num):
f=open(fileName, "r")
index = 1
for str in f:
str = str.rstrip()
if(index == num):
f.close()
return str
index += 1
f.close()
return None