Python 16

[python] 1699 제곱수의 합 (미해결)

https://www.acmicpc.net/problem/1699 고민: 입력한 수를 num이라 하자 sqrt(num)값이 가장 큰 제곱수일 것이다 그 수를 제외한 나머지의 sqrt()값이 가장 크다 계속 반복해서 1일 때까지 개수를 세본다 또, cnt 변수도 쓰겠다 ## 오답 # 입력, 기본 설정 import math num = int(input()) cnt = 0 tot = num # 제곱수 항의 최소 개수 구하기 while(tot!=0): #print(tot) # sqrtNum = int(math.sqrt(tot)) tot -= sqrtNum * sqrtNum cnt += 1 # 출력 print(cnt) 반례 -> 18 = 3^2+ 3^2 = 4^2 + 1^2 + 1^2 최소항의 개수는 2인데 3으..

Python/알고리즘 2022.07.03

[파이썬] 16503 괄호 없는 사칙연산

고민: 연산하는 부분을 어떻게 처리할지? 일일이 경우의 수를 나열하기에는 코드가 길다 -> calculate 함수를 이용해서 처리하였다 교훈: 1. 나눗셈 처리 "나눗셈 연산은 정수 나눗셈으로 몫만 취하며, 피연산자 중 하나가 음수이면 양수로 바꿔 계산한 결괏값에 음수를 취한다. " elif op == "/": if a * b 최대값 출력하기 # 처음 코드 if ans1 < ans2: print(ans1) print(ans2) else: print(ans2) print(ans1) # 나중 코드 print(min(ans1, ans2)) print(max(ans1, ans2)) min과 max 활용..

Python/알고리즘 2022.07.02

211112 파이썬 벼락치기

https://wikidocs.net/32#map 정수형 자료형 int 문자열 만드는 법 "Hello World" 'Python is fun' """Life is too short, You need python""" '''Life is too short, You need python''' 문자열 안에 '나 "포함 "Python's favorite food is perl" '"Python is very easy." he says.' 'Python\'s favorite food is perl' "\"Python is very easy.\" he says." 여러 줄로 출력 multiline = "Life is too short\nYou need python" >>> multiline=""" ... Life ..

Python 2021.11.13

참고용

자료형은 구분해야 함. ex) print(3, "Hello") //콤마를 이용해 여러 자료 출력 //사이에는 space 리스트 -어떤한 자료형 포함시킬 수 있다 주석 - # 또는 """ """ 자료형 변환 int() #정수형으로 변환 float() #실수형으로 변환 str() #문자형으로 변환 list() # 리스트로 변환 tuple() # 튜플로 변환 논리자료형(T / F) -비교연산자 -AND/OR/NOT print(not 3==4) //NOT 조건문 if 조건: //같은 들여쓰기로 구분 if 조건: else 조건: if 조건1: elif 조건2:

Python 2021.11.02

파이썬

x = 11 if x < 10 : print('Smaller') else : print('Bigger') x = 6 if x < 2 : print('Small') elif x < 20 : print('Medium') elif x < 10 ://확인안함 print('Medium') else ://확인안함 print('Ginormous') astr = "123" try://성공할경우 print("Hello") isInt = int(astr) print("World") except://실패할경우 isInt = "Integer로 변환할 수 없습니다." print('Done', isInt) # Hello # World # Done 123이 순서대로 출력됩니다. 가장 작은 수를 찾는 코드 완성하기 is 연산자는 N..

Python 2021.07.25