13.7. Exercises

  1. Fill in the left side of line 7 so that the following code runs without error

  2. Use a for loop to print out the last name, year of birth, and city for each of the people. (There are multiple ways you could do this. Try out some code and see what happens!)

13.7.1. Contributed Exercises

Use the enumerate() function to print the contents of the majors list, with the name of the major and its index position in the list one to a line like this:

0: Computer Science

The dictionary majors contains major codes as the key and major names as the value.

Write a function named find_major() that takes one parameter, a major code. If the major code exists in majors, your function should return a tuple where the first value is the major code and the second is the name of the major. If the major code doesn’t exist, return a tuple where the first value is None and the second is a string containing Error.

Print the name of the major with code 3084.

Write a function list_link that accepts two lists and returns a dictionary with the first list as the key and the second list as the value. Use enumerate link the two lists in a single for loop to create the dictionary. For example, list_link(['what','do','you','do'],[1,2,3,4]) should return {'what': 1, 'do': 4, 'you': 3}.

I’ve created a function Tuples_for_Tupelo that returns a string use unpacking to input a tuple of strings.

Parametric plotting time.

Using the code we created for parametric plotting. Create a function spiral(rmax,tlist) that makes a spiral that starts at rmax and spirals to r=0. This should auto scale based on the number of t values.

Create a function compare_str that accepts a letter and a string. The function should return the locations of letter in the string (in the form of a list) and ratio of the number of times the letter appears compared to the total number of letters(in the form of a float). The values should be returned as a tuple. For example compare_str('a','Is your mama a llama? I asked my friend Fred. No, is what Fred said.') should return ([9, 11, 13, 17, 19, 24, 55, 64],0.117).

Create a function tuplize that accepts two inputs and returns them in a tuple. The first input and then the second.

Fix the code below by adding just one symbol to the problematic line of code

You have attempted of activities on this page