본문 바로가기

분류 전체보기731

[복기] 최대공약수를 구해서 풀어보려다가 실패 # 해답코드 # 해답코드이자 심지어 풀이법도 쉬었다. bread = 197 milk = 152 student = 17 print('학생 한명이 갖게 되는 빵 갯수 : {}개'.format(bread // student)) print('학생 한명이 갖게 되는 우유 갯수 : {}개'.format(milk // student)) print('남는 빵 갯수: {}개'.format(bread % student)) print('남는 우유 갯수: {}개'.format(milk % student)) # 최대공약수를 구해서 어떻게 해보려고 했던 문제. # 최대공약수를 구하지 못해서 실패!! bread = 197 milk = 152 student = 17 max_common_number = 0 # 최대공약수 응용 파이썬 .. 2022. 4. 30.
[복기] 파이썬 복리이자 계산 # 정답코드 money = int(input('금액 입력: ')) rate = float(input('이율 입력: ')) term = int(input('기간 입력: ')) targetMoney = money # for문에서 변수로써 활용이 되는 i를 굳이 사용하지 않더라도, term이라고 ()안에 들어간 숫자만큼 # 반복되는건 처음알게 된것같다. for i in range(term): targetMoney += targetMoney * rate * 0.01 # 이것을 아래 print formating 까지 써서 넣어봤는데 에러가 계속 뜨더라; targetMoneyFormated = format(int(targetMoney),',') print('-'*30) print('이율: {}%'.format(ra.. 2022. 4. 30.
파이썬 천단위 구분 ,(컴마표시)ft.포멧팅 numbers = 10000000 print('{}초'.format(format(numbers,','))) 해당코드의 결과값은 10,000,000초 굉장히 간단해 보이는 코드이지만 아주 중한 코드라고 생각한다. 나에겐 다른 포메팅 형식에서 천단위 구분으로 컴마처리하는건 잘 모르겠는데. 아무튼 현재로써는 2중 format을 해줌으로써 ','를 해주면 결과값으로 천단위 구분이 된다. 2022. 4. 30.
파이썬 if문과 elif문의 활용 (거스름돈 버전) money50000 = 50000; money10000 = 10000; money5000 = 5000; money1000 = 1000 money500 = 500; money100 = 100; money50 = 50; money10 = 10 money50000Cnt = 0; money10000Cnt = 0; money5000Cnt = 0; money1000Cnt = 0 money500Cnt = 0; money100Cnt = 0; money50Cnt = 0; money10Cnt = 0 productPrice = int(input('상품 가격 입력: ')) payPrice = int(input('지불 금액 입력: ')) if payPrice > productPrice: changeMoney = payPrice.. 2022. 4. 30.