DBA가 되고 싶은 병아리

고민해봐야 할 문제 본문

프로그래밍/파이썬 스터디

고민해봐야 할 문제

미스틱스 2021. 4. 2. 15:23

character = {

    "name":"기사",

    "level":"12",

    "item":{

        "sword":"불꽃의 검",

        "armor":"풀플레이트"

        },

    "skill":["베기","세게 베기","아주 세게 베기"]

    }

for key in character:

    # for i in character:

    print(key,":",character[key])])

 

#결과

name~

level~

sword~

armor ~

skill ~

skill~

 

이런식으로 나와야 하는데 추가로 조건을 넣어야 하는 부분이 어렵게만 느껴짐..

 

age = 20

name = 'Swaroop'

 

print '{0} was {1} years old when he wrote this book'.format(name, age)

print 'Why is {0} playing with that python?'.format(name)

위에거는 문법이 최신 버전이 아니라서 그런건지는 몰라도 괄호를 넣지 않아서 그런지 문법 에러가 났었다.

해결책

age = 20

name = 'Swaroop'

 

print ('{0} was {1} years old when he wrote this book'.format(name, age))

print ('Why is {0} playing with that python?'.format(name)))(name)))

 

print 구문 처음과 끝에 괄호 표시 해줌

결과값

Swaroop was 20 years old when he wrote this book
Why is Swaroop playing with that python?

'프로그래밍 > 파이썬 스터디' 카테고리의 다른 글

반복문 2  (0) 2021.04.05
반복문 01  (0) 2021.04.05
제대로 못 풀었던 문제 1  (0) 2021.04.01
4단원 연습 문제  (0) 2021.03.31
딕셔너리 관련 내용  (0) 2021.03.30