목록전체 글 (92)
log.Sehee
모듈 1# calculator.pydef grade_calculator(s1, s2, s3, s4, s5): def total_grade(): total = s1 + s2 + s3 + s4 + s5 print(f"총점: {total}") return total def avg_grade(): avg = total_grade() / 5 print(f"평균: {avg}") return avg def pass_fail(): grades = [s1, s2, s3, s4, s5] pass_or_not = True for grade in grades: if grade >..
함수 1 def add(n1, n2): return print(f'{n1} + {n2} = {n1 + n2}')def sub(n1, n2): return print(f'{n1} - {n2} = {n1 - n2}')def mul(n1, n2): return print(f'{n1} * {n2} = {n1 * n2}')def div(n1, n2): return print(f'{n1} / {n2} = {n1 / n2}')def mod(n1, n2): return print(f'{n1} % {n2} = {n1 % n2}')def flo(n1, n2): return print(f'{n1} // {n2} = {n1 // n2}')def exp(n1, n2): return prin..
변수# 변수는 객체의 메모리 주소를 저장하여 객체를 참조한다.class Car: def __init__(self, color, length): self.color = color self.length = length def do_stop(self): print('STOP!!') def do_start(self): print('START!!')# 변수 = 객체car_1 = Car('red', 200)# car_1 변수가 가지고있는 주소값을 사용하여 do_stop() 실행car_1.do_stop() # STOP!! 얕은 복사 & 깊은 복사class Car: def __init__(self, color, length): sel..
함수# 내장 함수print('Hello python')numbers = [1, 2, 3, 4, 5]numbers.sort()numbers.reverse()# 사용자 함수def function1(num): print(num) function1(1) # 1 인수, 매개변수# n -> 매개변수, m -> 인수(인자)def function2(n): print(n) function2(m)# 매개변수가 n개일 때, *을 사용한다.def function3(*numbers): for number in numbers: print(number, end = '') print() function3(1, 2, 3, 4, 5) # 12345 return# return 키워드는 함..
반복문 5gear_a = int(input('GearA 톱니수 입력: '))gear_b = int(input('GearB 톱니수 입력: '))a, b = gear_a, gear_bcount = 0while a != b: count += 1 if b % gear_a != 0: b = gear_b * count b_count = count a = gear_a * count print(f'gearA: {a}, gearB: {b}')print(f'최초 만나는 톱니수(최소공배수): {b}톱니')print(f'gearA 회전수: {count}회전')print(f'gearB 회전수: {b_count}회전') 반복문 6for i in range(2021, 2032): ..
조건문 3import randomcom_num = random.randint(1, 2)user_select = int(input('홀/짝 선택: 1.홀 \t 2.짝 '))if com_num == 1: if user_select == com_num: print('빙고!! 홀수!!!') else: print('실패!! 홀수!!!')else: if user_select == com_num: print('빙고!! 짝수!!!') else: print('실패!! 짝수!!!')import randomcom_num = random.randint(1, 3)user_select = int(input('가위, 바위, 보 선택: 1.가위 \t 2.바위 \..