Introduction to Python Programming for Business and Social Science Applications. Frederick Kaefer. Читать онлайн. Newlib. NEWLIB.NET

Автор: Frederick Kaefer
Издательство: Ingram
Серия:
Жанр произведения: Зарубежная деловая литература
Год издания: 0
isbn: 9781544377452
Скачать книгу
Lines 2 and 3: gss_respondents = {“years”: (1972, 1991, 2014), “counts”: (24, 21, 43)}. Line 4: years = dict([1972, 24), (1991, 21), (2014, 43)]). Line 5: print(“line5:”, gss_respondents). Line 6: print(“line6:”, years). Line 8: gss_respondents.update(years). Line 9: print(“line9:”, gss_respondents). Line 11: gss_respondents[2014] = 45. Line 12: print(“line12:”, gss_respondents). Line 13: print(“the value for 1992 is: ”, gss_respondents.get(1992, “no value”)). Line 14: print(“the value for 1991 is: ”, gss_responsents.pop(1991, “no value”)). Line 15: print(“line15:”, gss_respondents). Line 17: gss_respondents.update(years). Line 18: print(“line18:”, gss_respondents).

      Back to Figure

      The output is titled, RESTART: I:\Fig 3_19 dictionary operations.py. There are eight lines of output as follows. Line 1: line5: {‘years’: (1972, 1991, 2014), ‘counts’: (24, 21, 43)}. Line 2: line6: {1972: 24, 1991: 21, 2014: 43}. Line 3: line9 {‘years’: (1972, 1991, 2014), ‘counts’: (24, 21, 43), 1972: 24, 1991: 21, 2014: 43}. Line 4: line12 {‘years’: (1972, 1991, 2014), ‘counts’: (24, 21, 43), 1972: 24, 1991: 21, 2014: 45}. Line 5: the value for 1992 is: no value. Line 6: the value for 1991 is: 21. Line 7: line15 {‘years’: (1972, 1991, 2014), ‘counts’: (24, 21, 43), 1972: 24, 2014: 45}. Line 8: line18 {‘years’: (1972, 1991, 2014), ‘counts’: (24, 21, 43), 1972: 24, 2014: 43, 1991: 21}.

       Back to image

      There are four lines of code as follows. Line 1: gss_respondents = {“counts”: (24, 21, 43)}. Line 2: # Modify the following line to get a list of just the values. Line 3: # in the dictionary using the values() method. Line 4: print(gss_respondents).

      Back to Figure

      There are 14 lines of code as follows. Line 1: # This Python code uses a function to look up. Line 2: # code meanings for GSS variables using dictionaries. Line 3: def code_lookup(codes): Line 4: region, happy = codes. Line 5: print(“line 5 – region, happy: ”, region, happy). Lines 6 through 9: region_dict = {1: “New England”, 2: “Middle Atlantic”, 3: “East North Central”, 4: “West North Central”, 5: “South Atlantic”, 6: “East South Central”, 7: “West South Central”, 8: “Mountain”, 9: “Pacific”}. Lines 10 and 11: happy_dict = {1: “Very happy”, 2: “Pretty happy”, 3: “Not too happy”, 8: “Don’t know”, 9: “No answer”, 0: “Not applicable”}. Line 12: return(region_dict[region], happy_dict[happy]). Line 14: codes = 3, 2. Line 15: print(“line 15 – codes: ”, codes). Line 16: response = code_lookup(codes). Line 17: print(“line 17 – response: ”, response). Line 18: print(“Interview region: “ + response [0]). Line 19: print(“Happiness level: “ + response[1]).

      Back to Figure

      The output is titled, RESTART: I:\Fig 3_21 Tuple and dictionary example.py. There are five lines of output as follows. Line 1: line 15 – codes: (3, 2). Line 2: line 5 – region, happy: 3 2. Line 3: line 17 – response: (‘East North Central’, ‘Pretty happy’). Line 4: Interview region: East North Central. Line 5: Happiness level: Pretty happy.

      Back to image

      There are eight lines of code as follows. Line 1: # This Python code works with a list object. Line 3: taxi_ride_info = [“da7a62fce04” , 180, 1.1, True] #This assigns four different objects to the list. Line 4: print(“The data type for the taxi_ride_info variable is: ”, type(taxi_ride_info)). Line 6: # The following code prints out the data type of each element of the list. Line 7: print(“The data type for the first element of taxi_ride_info is: ”, type(taxi_ride_info[0])). Line 9: print(“The data type for the second element of taxi_ride_info is: ”, type(taxi_ride_info[1])). Line 11: print(“The data type for the third element of taxi_ride_info is: ”, type(taxi_ride_info[2])). Line 13: print(“The data type for the fourth element of taxi_ride_info is: ”, type(taxi_ride_info[3])).

      Конец ознакомительного фрагмента.

      Текст предоставлен ООО «ЛитРес».

      Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.

      Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.

/9j/4RlaRXhpZgAASUkqAAgAAAAOAAABAwABAAAA0AIAAAEBAwABAAAAhAMAAAIBAwAEAAAAtgAA AAMBAwABAAAAAQAAAAYBAwABAAAABQAAABIBAwABAAAAAQAAABUBAwABAAAABAAAABoBBQABAAAA vgAAABsBBQABAAAAxgAAABwBAwABAAAAAQAAACgBAwABAAAAAgAAADEBAgAdAAAAzgAAADIBAgAU AAAA6wAAAGmHBAABAAAAAAEAACwBAAAIAAgACAAIAMDGLQAQJwAAwMYtABAnAABBZG9iZSBQaG90 b3Nob3AgQ0MgKFdpbmRvd3MpADIwMjA6MDg6MDUgMTc6MTQ6NDIAAAMAAaADAAEAAAD//wAAAqAE AAEAAABgCQAAA6AEAAEAAAC4CwAAAAAAAAAABgADAQMAAQAAAAYAAAAaAQUAAQAAAHoBAAAbAQUA AQAAAIIBAAAoAQMAAQAAAAIAAAABAgQAAQAAAIoBAAACAgQAAQAAAMgXAAAAAAAASAAAAAEAAABI AAAAAQAAAP/Y/+0ADEFkb2JlX0NNAAH/7gAOQWRvYmUAZIAAAAAB/9sAhAAMCAgICQgMCQkMEQsK CxEVDwwMDxUYExMVExMYEQwMDAwMDBEMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMAQ0LCw0O DRAODhAUDg4OFBQODg4OFBEMDAwMDBERDAwMDAwMEQwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM DAz/wAARCACgAIADASIAAhEBAxEB/90ABAAI/8QBPwAAAQUBAQEBAQEAAAAAAAAAAwABAgQFBgcI CQoLAQABBQEBAQEBAQAAAAAAAAABAAIDBAUGBwgJCgsQAAEEAQMCBAIFBwYIBQMMMwEAAhEDBCES MQVBUWETInGBMgYUkaGxQiMkFVLBYjM0coLRQwclklPw4fFjczUWorKDJkSTVGRFwqN0NhfSVeJl 8rOEw9N14/NGJ5SkhbSVxNTk9KW1xdXl9VZmdoaWprbG1ub2N0dXZ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