1000 1008 1085 1330 1427 1546 1712 2163 2292 2476 2557 2562 2588 2675 2739 2750 2751 2884 2914 3009 4101 4153 4344 5355 5717 8393 9498 10039 10171 10250 10718 10757 10809 10817 10818 10950 10952 10998 11022 11557 14681 15552 15596
1000 1001 1008 1085 1152 1330 1427 1546 1712 2163 2292 2476 2530 2557 2562 2588 2675 2739 2750 2751 2753 2754 2884 2908 2914 3009 3040 4101 4153 4344 5355 5622 5717 7287 7891 8393 9498 9506 9610 10039 10103 10171 10214 10250 10430 10718 10757 10809 10817 10818 10869 10886 10950 10952 10998 11022 11557 11650 14681 15552 15596
1001 1152 2530 2753 2754 2908 3040 5622 7287 7891 9506 9610 10103 10214 10430 10869 10886 11650
nums=input().split(' ')
print(int(nums[0])-int(nums[1]))
A, B=input().split()
print(int(A)-int(B))
간단한 계산 정도는 굳이 리스트로 만들지 않고
.split()으로 변수 하나씩 할당하기
A, B = input().split()
print(int(A)+int(B))
print(int(A)-int(B))
print(int(A)*int(B))
print(int(A)//int(B))
print(int(A)%int(B))
a, b = map(int,input().split())
print(a+b, a-b, a*b, a//b, a%b, sep='\n')
확실히 int함수 적는 걸 줄이고
코드 줄 자체를 줄인 것이 멋있어 보인다...!😲
그리고
sep='\n'
도 처음 알게된 문법.
찾아보거나 직접 실행해보진 않았는데
일단 보기에 앞의 출력할 것들을 한 줄씩 띄게 해주는 기능인 것 같다.
alphaNumList = [[],[], [],['A', 'B', 'C'], ['D', 'E', 'F'],['G','H','I'],['J','K','L'],['M','N','O'],['P','Q','R','S'],['T','U','V'],['W','X','Y','Z']]
grandmaWord=input()
callingTime=0
for i in grandmaWord:
for j in alphaNumList:
if i in j:
callingTime += alphaNumList.index(j)
print(callingTime)
#맘에 들어서 메모할려고 안 지움
아날로그 다이얼 전화기에 적힌 알파벳을 입력받아
전화하는 시간을 출력하는 문제인데,
if 문을 문자열 모임마다 쓸 수 있었겠지만
첫째로는 전부 입력하는 게 귀찮을 것 같아서
일단 다이얼을 돌리는 시간을 인덱스로 갖는 알파벳리스트를 만들었다.
그래서 입력받은 알파벳을 순서대로
알파벳리스트에 있는지 확인하여
인덱스만큼 돌리는 시간을 더하는 식으로 만들었다.
스스로 만들어놓고 뿌듯해서 주석까지 저렇게 적어놓았다.
이번 일차에서 가장 시간이 많이 걸렸던 문제
익숙치 않던 함수도 써봐서 기분이 좋았다.
-1이 나올 때까지 입력받은 자연수가 완전수인지 판별하고
출력도 합의 형식 또는 완전수가 아님을 알리는 문장으로 해야했다.
#맘에 들어서 남겨놓음
def isPerfect(num):
divisorList=[]
for n in range(1, num):
if num%n==0:
divisorList.append(n)
if sum(divisorList)==num:
return True
else:
return False
def outputSentence(num):
divisorList=[]
for n in range(1, num):
if num%n==0:
divisorList.append(n)
divisorList=list(map(str, divisorList))
return str(num)+' = '+" + ".join(divisorList)
resultList=[]
while True:
num=int(input())
if num == -1:
break
else:
if isPerfect(num)==True:
resultList.append(outputSentence(num))
else:
resultList.append('%d is NOT perfect.'%num)
for results in resultList:
print(results)
이번에는 없음