Midterm Review Questions
Python
Variables
Copy and paste the following variable definitions into a Python file:
x = 5
y = 12.2
z = 17
Instructions
Answer the following questions printing the output on it's own line with the question number in front of it. E.g.,
Questions
1. Write a command(s) that prints the sum of the value of masses.
2. Write a command(s) that prints the sum of the 5th, 6th, 7th, and 8th values in masses (obtained by looking up the values using Python, not by typing them in)
3. Write a function halfval_if_between_10_and_20(val) that takes a value as input and returns the same value if it is less than or equal to 10 or greater than or equal to 20 and returns twice the value if it is between 10 and 20. Print the output of this function for val = 10 and val = 42.
4. Write a command(s) that prints z plus the logarithm (base 10; i.e. log10) of y. Hint: you may need to import a module to do this.
5. Write a command(s) that prints the number of a's in dna.
6. Write a function combine_strings(string1, string2) that takes two strings as arguments and returns the combination of the two strings with a space between them as a single string. Print the output of this function for string1 = 'ultimate' and string2 = 'answer'.
7. write a function combine_strings_multivalue(string_list) that takes a list of lists as input with each sublist containing a pair of strings [string1, string2]. The function should loop over the sublists, determine the value of combine_strings(string1, string2) for each pair of strings, and return a list of those values. Print the output of this function using mystrings as the input.
8. Write a function increment_by_pt5(start_num, max_num) that takes two numbers as inputs (a starting point and a maximum value), and returns a list that includes a progression of numbers starting with start_num and increasing by 0.5 for each subsequent number, ending with the last number that is less than or equal to max_num. Use a while loop. Print the output of this function for start_num = 10.3, max_num = 20.
9. Write a for loop (using commands, not a function) that prints the integers from 2 to 10.
Python Solutions (remember, there are lots of different ways to do things; these are just the approaches I took)
Databases
1. Download a copy of the Portal database.
2. Write a query that returns the number of individuals of each species occuring at the site. The output of the query should be one column that contains the full species name and another column containing the counts of individuals. Save this query as Number of Individuals By Species.
3. Write a query that returns all of the fields from the Portal Main table where the species is in the genus Dipodomys (i.e. has a speciesID of DM, DO, or DS) and 1997 <= year <= 2002. Save thie query as Dipodomys From 1997 to 2002.
4. Write a query (it might need to be a set of nested queries) that returns the average number of individuals sampled per plot grouped by Plot Type. Save this query as Average Number of Individuals Per Plot by Plot Type.

