|
| 1 | +dic1 = {} |
| 2 | +dic2 = dict() |
| 3 | +dic = {'name':'pey', 'phone':'01051035773'} |
| 4 | +print(dic['name']) #pey |
| 5 | +dic['birth'] = '1212' |
| 6 | +print(dic) #랜덤출력 |
| 7 | +del dic['name'] |
| 8 | +print(dic.keys()) #key값 |
| 9 | +print(dic.values()) #value값 |
| 10 | + |
| 11 | +b = list(dic.keys()) #리스트로 반환 |
| 12 | +print(b) |
| 13 | + |
| 14 | +b = dic.items() #튜플로써 묶여진 형태의 값을 반환 |
| 15 | +print(b) |
| 16 | + |
| 17 | +#dic.clear() #지우기 |
| 18 | +print(dic.get('name')) #None |
| 19 | +print(dic.get('birth')) #1212 |
| 20 | +dic.get('name','sm') #해당 key가 없으면 default로 sm |
| 21 | +'name' in dic #key가 있는지 조사 |
| 22 | + |
| 23 | +#영화 별점주기 실습 |
| 24 | +#dic 안에 dic |
| 25 | +movies = {'홍길동':{'베테랑':5.0,'암살':4.5},'고길동':{'베테랑':3.5,'암살':3.0}} |
| 26 | +print(movies['홍길동']) #홍길동이 준 점수들 |
| 27 | +#print(movies.get('홍길동')) |
| 28 | +print(movies['홍길동']['암살']) #암살 점수만 |
| 29 | +#print(movies.get('홍길동').get('암살')) |
| 30 | + |
| 31 | +#대소문자 구분 |
| 32 | +# == != < > <= >= and or not 조건문에 응용 |
| 33 | +answer = input("Would you like express shipping? : ") |
| 34 | +answer = answer.lower() |
| 35 | +if answer == "yes" : |
| 36 | + print("That will be an extra $10") |
| 37 | + |
| 38 | +pocket = ['paper', 'money', 'cellphone'] |
| 39 | +if 'card' in pocket: pass # pass 사용법. 한 줄일 때 사용법 |
| 40 | +else: print("카드를 꺼내라") |
| 41 | + |
| 42 | +a = [(1,2), (3,4), (5,6)] |
| 43 | +for (first, last) in a : #a의 튜플 하나씩 가져오는데 first, last로 이름을 붙이고 |
| 44 | + print(first + last) #first+last 해서 출력 |
| 45 | + |
| 46 | +for steps in range(1,10,2) : |
| 47 | + print(steps) #1,3,5,7,9 |
| 48 | + |
| 49 | +#구구단 출력 |
| 50 | +#print하면 기본적으로 줄바꿈이 되는데 end=" " 옵션을 주면 |
| 51 | +#줄바꿈 하지않고 " " 공백 한 칸 출력 |
| 52 | +for i in range(2,10): |
| 53 | + for j in range(1,10): |
| 54 | + print('{0:d}*{1:d}={2:d}'.format(i,j,i*j), end=" ") |
| 55 | + print('') |
| 56 | + |
| 57 | +#turtle 라이브러리 불러오기 |
| 58 | +import turtle |
| 59 | +#for steps in range(4): #4번 움직여라 |
| 60 | +# turtle.forward(100) |
| 61 | +# turtle.right(90) |
| 62 | + |
| 63 | +nSides = 7 # 7각형 안에 7각형 |
| 64 | +for steps in ['red','blue','green','black','yellow','cyan','purple']: |
| 65 | + turtle.color(steps) |
| 66 | + turtle.forward(100) |
| 67 | + turtle.right(360/nSides) |
| 68 | + for moresteps in range(nSides): |
| 69 | + turtle.forward(50) |
| 70 | + turtle.right(360/nSides) |
| 71 | +input("") |
| 72 | + |
| 73 | +#여러 줄에 걸쳐있는 것을 하나의 문자열로 선언 |
| 74 | +prompt = """ |
| 75 | +1. Add |
| 76 | +2. Del |
| 77 | +3. List |
| 78 | +4. Quit |
| 79 | +
|
| 80 | +Enter number: """ |
| 81 | + |
| 82 | +number = 0 |
| 83 | +while number != 4: |
| 84 | + print(prompt, end="") |
| 85 | + number = int(input()) |
| 86 | +# 반복문 나갈 때 break / 조건으로 분기하고 싶으면 continue |
0 commit comments