오늘은 연습삼아 파이썬 기초문법을 활용하여 간단한 기능의 함수를 만들어보았다.
def find_number(number_list):
even_list=[]
for number in number_list:
if number%2==0:
even_list.append(number)
return even_list
print(find_number([1, 2, 3, 6, 3, 2, 4, 5, 6, 4]))
def count_even_number(number_list):
count=0
for number in number_list:
if number % 2 == 0:
count=count+1
return count
print(count_even_number([1, 2, 5, 6]))
def sum_list(number_list):
sum=0
for number in number_list:
sum=number+sum
return sum
print(sum_list([1, 2, 3, 5]))
def check_gender(pin):
s=pin.split('-')[1][0]
if int(s)%2==0:
s='여성'
else:s='남성'
print(s)
my_pin = '200101-4012345'
check_gender(my_pin)
def check_gender(pin):
s = pin.split('-')[1][0]
s = '여성' if int(s)%2==0 else '남성'
print(s)
my_pin = '200101-4012345'
check_gender(my_pin)
김똑똑님한테 얻은 꿀팁인데요. 코드 입력할때 ```python 이렇게 쓰면 이뻐진다네요 ㅎㅎ