LIKE A DIAMOND

[파이썬009] 파이펫 친구 만들기 본문

notUsed_STUDY

[파이썬009] 파이펫 친구 만들기

OPENLUNCH 2020. 4. 25. 20:08
728x90
반응형

이전의 코드

print("Hello World")

print("안녕하세요. 좋은 하루입니다.")

cat = {

"name" : "멍멍이",

"age" : 5,

"hungry" : True,

"weight" : 5,

"photo" : "(=^___^=)"

}

def feed(pet) :

if pet["hungry"] == True :

pet["hungry"] = False

pet["weight"] = pet["weight"]+1

else :

print(pet["name"] + "는(은) 이미 배가 불러요.")

print(cat)

feed(cat)

print(cat)

feed(cat)

//

찍찍이 넣기

1. cat 부분 복사 후 바로 아래 붙여 넣기

cat = {

"name" : "멍멍이",

"age" : 5,

"hungry" : True,

"weight" : 5,

"photo" : "(=^___^=)"

}

2. 붙여넣기한 부분의 내용 변경(이름.나이,무게,그림 바꿈)

mouse = {

"name" : "찍찍이",

"age" : 3,

"hungry" : True,

"weight" : 1,

"photo" : "<:3~~~~~~~~~"

}

3. 찍찍이 출력하기

출력부분

print(cat)

print(mouse)

feed(cat)

print(cat)

print(mouse)

feed(cat)

print(cat)

print(mouse)

 

4. 실행

// 찍찍이는 여전히 배가 고프다.

멍멍이와 찍찍이에게도 동시에 먹이를 주려고 한다 [For 반복문, list 활용)

**for 반복문 예시

*for i in range(3) : 반복문 3번 반복

*for item i [list] : 리스트의 데이터 순서대로 넣기

5. 먹이줄 리스트 생성

pets = [cat, mouse]

6. 리스트를 반복문에 적용 후 출력한다.

for pet in pets :

print(pet)

feed(pet)

print(pet)

feed(pet)

7.출력

8.

추천1

https://wikidocs.net/book/2

추천2

http://byteofpython-korean.sourceforge.net/byte_of_python.html

728x90
반응형
Comments