파이썬 10

C

[ BaekJoon - Python & Java ] 단계별로 풀기 3. For

단계별로 풀기 - 3. for 2749 곱셈 n = int(input()) a = 1 while a < 10: print(f"{n} * {a} = {n * a}") a += 1 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int j = sc.nextInt(); for(int i = 1; i < 10; i++){ System.out.println(j + " * " + i + " = " + j * i); } sc.close(); } } 10950 A + B - 3 n = int(input()) while n != 0: a, b = m..

Algorithm/BOJ 2021.12.09

C

[ Python ] 입출력(I/O) 속도 빠르게 하기

백준 파이썬 문제를 풀다보면 시간초과가 뜨는 경우 입출력 방법을 바꿔줌으로써 해결하는 방법이 있다. import sys input = sys.stdin.readline print = sys.stdout.write 위 처럼 input()과 print()를 덮어씌워버린다. # 주의할 점 바꾸고 나면, input()은 개행문자 "\n"까지 읽어들이기 때문에 .rstrip()등으로 지워주어야 하고 import sys input = sys.stdin.readline n = input() # "1"을 입력 할 때, print(list(n)) # ['1', '\n'] print([int(n)]) # [1] print(list(n.rstrip())) # ['1'] print()는 출력 방식이 다음과 같이 바뀌어 버린다..

Dev/Python 2021.12.06

C

[ BaekJoon - Python ] 단계별로 풀기 1. 출력 입출력 (I/O)

단계별로 풀기 - 1. 입출력 # 참조 링크 파이썬으로 정수 입력 받기 1000번 A + B a, b = map(int, input().split()) print(a+b) 1001번 A - B a, b = map(int, input().split()) print(a - b) 10998번 A * B a, b = map(int, input().split()) print(a * b) 1008번 A / B a, b = map(int, input().split()) print(a/b) 10869번 사칙연산 a, b = map(int, input().split()) print(a+b) print(a-b) print(a*b) print(int(a/b)) print(a % b) 10430 나머지 a, b, c = ma..

Algorithm/BOJ 2021.11.30

C

[ Python ] 3항 연산자 (Ternary Operator) 에서 break, return을 사용 할 수 없는 이유

while True: a, b = map(int, input().split()) print(a + b) if (a + b) else break 줄 수를 줄이기 위해 위와 같이 코드를 작성하자, break에 빨간 줄이 그어지며 SyntaxError: invalid syntax가 발생했다. Python에서 3항 연산자의 사용 방식은 다음과 같은데, if else 여기서 는 expression이며, break, return과 같은 명령어는 statement라고 한다. expression와 statement을 구분하는 방법은 출력할 수 있거나, 변수에 값을 삽입할 수 있으면 expression, 할 수 없으면 statement 이다. expression의 예 2 + 2 3 * 7 1 + 2 + 3 * (8 **..

Dev/Python 2021.10.23

C

[ Python ] File "<stdin>", line 1 SyntaxError: invalid syntax

#에러 전문 >>> set PYTHONIOENCODING=utf8 ; if ($?) { py } "d:\dev\Repositiory\Python-prac\py_basic\prac3.py" File "", line 1 set PYTHONIOENCODING=utf8 ; if ($?) { py } "d:\dev\Repositiory\Python-prac\py_basic\prac3.py" ^ SyntaxError: invalid syntax # 해결법 code-runner 실행 설정에서 "code-runner.executorMap": { "python": "set PYTHONIOENCODING=utf8 | py" } 파이썬 항목을 이렇게 바꿔주면 된다. # 에러 발생이유 이미 실행되어있는 파이썬 인터프리터 내부..