-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary.py
58 lines (47 loc) · 1.74 KB
/
dictionary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Scroll down to see the answers!
# 1 Create a user profile for your new game. This user profile will be stored in a dictionary with keys: 'age', 'username', 'weapons', 'is_active' and 'clan'
user_profile = {
'age': 20,
'username': 'brandon',
'weapons': ['knife'],
'is_active': True,
'clan': True
}
# 2 iterate and print all the keys in the above user.
print(user_profile.keys())
# 3 Add a new weapon to your user
# user_profile.update({'new_weapon':'gun'})
user_profile['weapons'].append('gun')
# 4 Add a new key to include 'is_banned'. Set it to false
user_profile.update({'is_banned': False})
# 5 Ban the user by setting the previous key to True
user_profile.update({'is_banned': True})
# 6 create a new user2 my copying the previous user and update the age value and username value.
user2 = user_profile.copy()
user2.update({'age': 18})
user2.update({'username': 'Hannes'})
print(user2)
# Solutions:
# 1 Create a user profile for your new game. This user profile will be stored in a dictionary with keys: 'age', 'username', 'weapons', 'is_active' and 'clan'
# user = {
# 'age': 22,
# 'username': 'Shogun',
# 'weapons': ['katana', 'shuriken'],
# 'is_active': True,
# 'clan': 'Japan'
# }
# 2 iterate and print all the keys in the above user.
# print(user.keys())
# 3 Add a new weapon to your user
# user['weapons'].append('shield')
# print(user)
# 4 Add a new key to include 'is_banned'. Set it to false
# user.update({'is_banned': False})
# print(user)
# 5 Ban the user by setting the previous key to True
# user['is_banned'] = True
# print(user)
# 6 create a new user2 my copying the previous user and update the age value and username value.
# user2 = user.copy()
# user2.update({'age': 100, 'username': 'Timbo'})
# print(user2)