인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

wpghfj's profile image
wpghfj

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

txt 파일 input 문제

Resolved

Written on

·

1.5K

·

Edited

1

안녕하세요 1강 문제를 푸는데 계속 아래와 같은 에러가 뜹니다..

txt파일과 py파일은 한 폴더 안에 존재합니다. (vscode를 이용 중입니다.)

open('./input.txt', 'rt')

open('./input', 'rt')

open('input.txt', 'rt')

open('input', 'rt') 등 다양한 방법으로 open해봐도 문제가 생기는군요..

python코딩-테스트

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

주소를 풀네임으로 하니까 되네요. 특히 풀네임 주소를 쓸때 '\' 로 하지 말고 '/'로 구분하면서 주소를 쓰세요.

import sys
sys.stdin=open('c:/Users/gram/Desktop/vcpython/input.txt', 'r')
n, k=map(int, input().split())
cnt=0
for i in range(1, n+1):
    if n%i==0:
        cnt+=1
    if cnt==k:
        print(i)
        break
else:
    print(-1)
wpghfj's profile image
wpghfj

asked

Ask a question