Читать книгу Introduction to Python Programming for Business and Social Science Applications - Frederick Kaefer - Страница 96

End-of-Chapter Exercises

Оглавление

 3.1. Identify the names of the functions and methods used in the following code.Description

 3.2. Use the input() function learned in Chapter 2 to input three strings (a first name, a middle initial, and a last name). Concatenate these strings together with a space between each, storing the result in a new variable. Print out the concatenated string.

 3.3. Define a list of survey response values (5, 7, 3, and 8) and store them in a variable. Next define a tuple of respondent ID values (1012, 1035, 1021, and 1053). Use the .append() method to append the tuple to the list. Print out the list. What happened?

 3.4. Create the list of responses from Exercise 3.3 (values 5, 7, 3, 8). Next add the response “0” to the end of the list using the .append() method. Next add the response “6” to the list between the values 7 and 3 (in what will be the third position in the list) using the .insert() method. Print out the list to verify that you made the changes correctly.

 3.5. Create the tuple of survey respondent IDs from Exercise 3.3 (1012, 1035, 1021, and 1053). Next attempt to add the respondent ID “1011” to the end of the tuple using the .append() method. What happens when you attempt to run the code?

 3.6.Write Python code to define a dictionary named taxi_trip_info with the following key value pairs:Print out the dictionary to show what it looks like. Also print out just the Trip_miles value from the dictionary.

 3.7. Write Python code to define a list of taxi trip durations in miles (use values 1.1, 0.8, 2.5, 2.6). Also define a tuple of fares for the same number of trips (use values “$6.25,” “$5.25,” “$10.50,” “$8.05”). Store both the tuple and the list as values in a dictionary called trips, with keys “miles” and “fares.” Print out the dictionary to show what it looks like.

Introduction to Python Programming for Business and Social Science Applications

Подняться наверх