Zero to Mastery course Python

Run Settings
LanguagePython
Language Version
Run Command
# Exercise Dictionary Methods # Scroll to see 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' # 2 iterate and print all the keys in the above user. # 3 Add a new weapon to your user # 4 Add a new key to include 'is_banned'. Set it to false # 5 Ban the user by setting the previous key to True # 6 create a new user2 my copying the previous user and update the age value and username value. #ANSWER BELOW user_profile = { 'username' : 'Elpiberats', 'age' : 41, 'weapons' : None, 'is_active' : True, 'clan' : None } # print(user_profile.items()) user_profile.update({'weapons' : 'Katana'}) #OR user_profile['weapons'] = 'Katana' user_profile.update({'is_banned' : False}) user_profile.update({'is_banned' : True}) #OR user_profile['is_banned'] = True user_profile2 = user_profile user_profile2.update({'username' : 'Chiquitik', 'age' : 40}) print(user_profile2)
# https://www.w3schools.com/python/python_ref_set.asp #Scroll to bottom to see solution # You are working for the school Principal. We have a database of school students: school = {'Bobby','Tammy','Jammy','Sally','Danny'} #during class, the teachers take attendance and compile it into a list. attendance_list = ['Jammy', 'Bobby', 'Danny', 'Sally'] #using what you learned about sets, create a piece of code that the school principal can use to immediately find out who missed class so they can call the parents. (Imagine if the list had 1000s of students. The principal can use the lists generated by the teachers + the school database to use python and make his/her job easier): Find the students that miss class! print(attendance_list.difference(school))
# https://www.w3schools.com/python/python_ref_set.asp #Scroll to bottom to see solution # You are working for the school Principal. We have a database of school students: school = {'Bobby','Tammy','Jammy','Sally','Danny'} #during class, the teachers take attendance and compile it into a list. attendance_list = ['Jammy', 'Bobby', 'Danny', 'Sally'] no_attendance_students = school.difference(attendance_list) print(f'The following students are missing classes {no_attendance_students}')
#https://www.w3schools.com/python/python_ref_dictionary.asp # Exercise Dictionary Methods # Scroll to see 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' # 2 iterate and print all the keys in the above user. # 3 Add a new weapon to your user # 4 Add a new key to include 'is_banned'. Set it to false # 5 Ban the user by setting the previous key to True # 6 create a new user2 my copying the previous user and update the age value and username value. #ANSWER BELOW user_profile = { 'username' : 'Elpiberats', 'age' : 41, 'weapons' : None, 'is_active' : True, 'clan' : None } # print(user_profile.items()) user_profile.update({'weapons' : 'Katana'}) #OR user_profile['weapons'] = 'Katana' user_profile.update({'is_banned' : False}) user_profile.update({'is_banned' : True}) #OR user_profile['is_banned'] = True user_profile2 = user_profile user_profile2.update({'username' : 'Chiquitik', 'age' : 40}) print(user_profile2)
Editor Settings
Theme
Key bindings
Full width
Lines