my_cat = {'size': 'fat', 'color': 'gray', 'disposition': 'loud'}
print(my_cat['size'])
print('My cat has ' + my_cat['color'] + 'fur.')
spam = ['cats', 'dogs', 'moose']
bacon = ['dogs', 'moose', 'cats']
print(spam == bacon)
eggs = {'name': 'Zophie', 'species': 'cat', 'age': '8'}
ham = {'species': 'cat', 'age': '8', 'name': 'Zophie'}
print(eggs==ham)
eggs = {'name': 'Zophie', 'age': '7'}
spam['color']
birthdays = {'アリス': '4/1', 'ボブ': '12/12', 'キャロル': '4/4'}
while True:
print('名前を入力してください:(終了するにはEnterだけ押してください)')
name = input()
if name == '':
break
if name in birthdays:
print(name + 'の誕生日は' + birthdays[name])
else:
print(name + 'の誕生日は未登録です。')
print('誕生日を入力してください')
bday = input()
birthdays[name] = bday
print('誕生日データベースを更新しました')
spam = {'color': 'red', 'age': 42}
for v in spam.values():
print(v)
for k in spam.keys():
print(k)
for i in spam.items():
print(i)
print(spam.keys())
print(list(spam.keys()))
for k, v in spam.items():
print('Key: ' + k + ' Value: ' + str(v))
spam = {'name': 'Zophie', 'age': 7}
print('name' in spam.keys())
print('Zophie' in spam.values())
print('color' in spam.keys())
print('color' not in spam.keys())
print('color' in spam)
picnic_items = {'apples': 5, 'cups': 2}
print('I am bringing ' + str(picnic_items.get('cups', 0)) + ' cups.')
print('I am bringing ' + str(picnic_items.get('eggs', 0)) + ' cups.')
print('I am bringing ' + str(picnic_items['eggs']) + ' eggs.')
spam = {'name': 'Pooka', 'age': 5}
if 'color' not in spam:
spam['color'] = 'black'
spam = {'name': 'Pooka', 'age': 5}
print(spam.setdefault('color', 'black'))
print(spam)
print(spam.setdefault('color', 'white'))
print(spam)
message = 'It was a bright cold day in April, and the clocks were striking thirteen.'
count = {}
for character in message:
count.setdefault(character, 0)
count[character] = count[character] + 1
print(count)
import pprint
message = 'It was a bright cold day in April, and the clocks were striking thirteen.'
for character in message:
count.setdefault(character, 0)
count[character] = count[character] + 1
pprint.pprint(count)
the_board = {'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
the_board = {'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
'mid-L': ' ', 'mid-M': 'X', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
the_board = {'top-L': 'O', 'top-M': 'O', 'top-R': 'O',
'mid-L': 'X', 'mid-M': 'X', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
the_board = {'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
def print_board(board):
print(board['top-L'] + '|' + board['top-M'] + '|' + board['top-R'])
print('-+-+-')
print(board['mid-L'] + '|' + board['mid-M'] + '|' + board['mid-R'])
print('-+-+-')
print(board['low-L'] + '|' + board['low-M'] + '|' + board['low-R'])
print_board(the_board)
the_board = {'top-L': 'O', 'top-M': 'O', 'top-R': 'O',
'mid-L': 'X', 'mid-M': 'X', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
print_board(the_board)
the_board = {'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
def print_board(board):
print(board['top-L'] + '|' + board['top-M'] + '|' + board['top-R'])
print('-+-+-')
print(board['mid-L'] + '|' + board['mid-M'] + '|' + board['mid-R'])
print('-+-+-')
print(board['low-L'] + '|' + board['low-M'] + '|' + board['low-R'])
turn = 'X'
for i in range(9):
print_board(the_board)
print(turn + 'の番です。どこに打つ?')
move = input()
the_board[move] = turn
if turn == 'X':
turn = 'O'
else:
turn = 'X'
print_board(the_board)
all_guests = {'アリス': {'リンゴ': 5, 'プレッツェル': 12},
'ボブ': {'ハムサンド': 3, 'りんご': 2},
'キャロル': {'コップ': 3, 'アップルパイ': 1}}
def total_brought(guests, item):
num_brought = 0
for k, v in guests.items():
num_brought = num_brought + v.get(item, 0)
return num_brought
print('持ち物の数:')
print(' - リンゴ' + str(total_brought(all_guests, 'リンゴ')))
print(' - コップ' + str(total_brought(all_guests, 'コップ')))
print(' - ケーキ' + str(total_brought(all_guests, 'ケーキ')))
print(' - ハムサンド' + str(total_brought(all_guests, 'ハムサンド')))
print(' - アップルパイ' + str(total_brought(all_guests, 'アップルパイ')))