목록Programming (97)
59doit
귀함수 def Counter(n) : if n == 0 : # 0 호출하면 종료 return 0 else : Counter(n-1) #재귀 print(n, end=' ') Counter(5) # 1 2 3 4 5 재귀함수 누적합 def Add(n) : if n==1 : return 1 else : result = n+Add(n-1) #재귀 print(n, end = ' ') return result print ("n=1 : ", Add(1)) # n=1 : 1 print ("\nn=5 : ", Add(5)) # # 2 3 4 5 # n=5 : 15
1. 현재잔고를 조회하는 사용자정의 함수를 정의하세요. 조건: 1) 외부함수 1개 (현잔고, 입금액, 출금액) 2) 내부함수 1개 현잔고,입금액, 출금액을 계산하여 업데이트된 잔고를 계산 3) 현잔고 : 10,000원 , 입금액 : 5,000원, 출금액 : 8,000원 4) 업데이트된 잔고를 프린트하세요 # 현잔고:balance 입금액:money, 출금액:withdraw a=balance = 10000 b=money = 5000 c=withdraw = 8000 def x(a,b,c) : # 임의변수를만들어야함 bal = a # 외부함수에는 자료생성 mon = b wit = c def y() : # 출금 sum = bal+mon-wit # 외부함수에서 만든 자료를 연산함 # 결과값 = 현잔고 + 입금액 -..
가변함수 튜플확인 def test(*arg) : print(type(arg)) test(1,2) # 튜플형 def Func1 (name, *names) : print(name) print(*names) Func1("가","나","다") # # 가 # 나다 튜플형 _ 한줄로 print def Func1 (name, *names) : print(name,end=' ') print(*names) Func1("가","나","다") # # 가 나 다 end 뒤에 쌍따옴표 말고 ->('') 여야 한줄에 나옴 print는 기본적으로 한줄띄어서 출력된다 딕트형 def emp_func(name,age,**other) : print(name) print(age) print(other) emp_func("JAIN", 25 ..
dataset = list(range(1,7)) print(dataset) # [1, 2, 3, 4, 5, 6] print('len=',len(dataset)) # len= 6 print('sum=',sum(dataset)) # sum= 21 print('max=',max(dataset)) # max= 6 print('min=',min(dataset)) # min= 1 import 함수 ; 외부 모듈을 포함시켜야 사용 할 수 있는 함수 1) 모듈명.함수() 수학/통계 함수 statistics모듈을 import 해야한다 즉, 평균,중위수는 내장함수가 아니기 때문에 모듈을 import해야한다 dataset = list(range(1,7)) print(dataset) # [1, 2, 3, 4, 5, 6] im..