5.2
#coding=utf-8 #仅选取原题中几个小问,避免代码段太长 string = 'GGwp' print("Is string.lower() == 'ggwp'? I predict True.") print(string.lower() == 'ggwp') print("Is string.lower() == 'goodgame'? I predict False.") print(string.lower() == 'goodgame') num = 3 print("Is 3 < 4?I predict True.") print(3 < 4) print("Is 3 < 2?I predict False.") print(3 < 2) major = ['ESL','PGL','MDL'] print("Is ESL in major?I predict True.") print('ESL' in major) print("Is GESC in major?I predict False.") print('GESC' in major)
5.3
alien_color = 'green' if alien_color == 'green': print("YOU GET 5 POINTS") alien_color = 'yellow' if alien_color == 'green': print("YOU GET 5 POINTS")
5.4
alien_color = 'green' if alien_color == 'green': print("YOU GET 5 POINTS") else: print("YOU GET 10 POINTS") alien_color = 'yellow' if alien_color == 'green': print("YOU GET 5 POINTS") else: print("YOU GET 10 POINTS")
5.8
users = ['admin','kky','ppd','puppey','solo'] for user in users: if user == 'admin': print("Hello admin,would you like to update the game?") else: print("Hello " + user + ", there is some the new update.")
5.9
users = ['admin','kky','ppd','puppey','solo'] users = [] if len(users): for user in users: if user == 'admin': print("Hello admin,would you like to update the game?") else: print("Hello " + user + ", there is some the new update.") else: print("we need to find some users")
5.11
nums = range(1,10) for num in nums: if num == 1: print("1st") elif num == 2: print("2nd") elif num == 3: print("3rd") else: print(str(num) + "th")
============================================================================
6.1
message = {'first_name': 'jacky', 'second_name': 'mao', 'age': 26, 'club': 'Fnc'} print(message['first_name']) print(message['second_name']) print(message['age']) print(message['club'])
6.2
fnums = {'Zhang': 3, 'li': 4, 'Wang': 5, 'Zhao': 6, 'Sun': 7} for key,value in fnums.items(): print(key + " like " + str(value))
6.5
rivers = { 'nile': 'egypt', 'Changjiang': 'china', 'Amazon': 'brazil' } for key,value in rivers.items(): print("The " + key.title() + " runs through " + value.title() ) print("") for key in rivers.keys(): print(key) print("") for value in rivers.values(): print(value)
6.6
player_1 = {'first_name': 'Jacky', 'second_name': 'Mao', 'age': 26, 'club': 'Fnc'} player_2 = {'first_name': 'Artour', 'second_name': 'Babaev', 'age': 21, 'club': 'EG'} player_3 = {'first_name': 'Liangzhi', 'second_name': 'Hu', 'age': 25, 'club': 'Newbee'} people = [player_1, player_2, player_3] for player in people: print(player)
6.10
fnums = { 'Zhang': [3, 4], 'li': [4, 5], 'Wang': [5, 6], 'Zhao': [6, 7], 'Sun': [7, 8] } for key,value in fnums.items(): print(key + " like :" ) for num in value: print("\t" + str(num))