_won_
wonprogrammer
_won_
전체 방문자
오늘
어제
  • 분류 전체보기
    • woncoding
      • TIL
      • WIL
    • source Code
      • Python
      • Programmers
      • BAEKJOON

블로그 메뉴

  • 방명록

티스토리

Github · Wonprogrammer
hELLO · Designed By 정상우.
_won_

wonprogrammer

source Code/Python

Python | py_basic_week1

2022. 9. 1. 14:41

- py_basic_week1 [변수 / 리스트 / 딕셔너리 / 조건,반복문 / 함수]

 

1. [enumerate.py]

 

fruits = ['사과', '배', '감', '귤','귤','수박','참외','감자','배','홍시','참외','오렌지']

for i, fruit in enumerate(fruits):
    print(i, fruit)
    if i == 4:
        break

 

 

2. [list_prac.py]

 

짝수 몇개?

num_list = [1, 2, 3, 6, 3, 2, 4, 5, 6, 2, 4]

count = 0

for i in num_list :
    if i % 2 == 0 :
        count += 1

print(count)

 

전체 합은?

num_list = [1, 2, 3, 6, 3, 2, 4, 5, 6, 2, 4]

sum = 0

for i in num_list :
    sum = sum + i

print(sum)

 

가장 큰 수는?

num_list = [1, 2, 3, 6, 3, 2, 4, 5, 6, 2, 4]

max_num = 0

for i in num_list :
    if max_num < i :
        max_num = i


print(max_num)

 

 

 

3. [def_prac.py]

 

def identify(num):
    sex_identify = int(num.split('-')[1][0])
    if sex_identify % 2 == 0:
        print('Female')
    else:
        print('Male')

my_num = '930516-2345678'

identify(my_num)

'source Code > Python' 카테고리의 다른 글

Python | py_basic_week1  (0) 2022.09.02
Python | poo_game.py  (0) 2022.09.01
Python | memory_game.py  (0) 2022.08.26
Python | weapon_game.py  (0) 2022.08.25
Python | calculator.py  (0) 2022.08.18
    'source Code/Python' 카테고리의 다른 글
    • Python | py_basic_week1
    • Python | poo_game.py
    • Python | memory_game.py
    • Python | weapon_game.py
    _won_
    _won_
    Coding Practice blog

    티스토리툴바