Question: Question 3: Strings and filing in Python 3.6 (wth is a file actually, is it another library???) a) Write a function named binary_to_decimal that parses

Question 3: Strings and filing in Python 3.6 (wth is a file actually, is it another library???)

a) Write a function named binary_to_decimal that parses a binary number as a string into a decimal form, and returns it as an integer. You can assume that the string is never empty and only contains characters 0 or 1.

b) Write a function named uncompressed that takes a compressed string as an input and returns an uncompressed string, where each alphabetic character is preceded by a single digit, indicating the number of times that the character should be entered in the uncompressed version of the string. For example:

The uncompressed version of 2a5b1c is aabbbbbc

The uncompressed version of 1a1b2c is to abcc

The uncompressed version of 1a9b3b1c is abbbbbbbbbbbbc

c) Write a function named get_base_counts2 by modifying get_base_counts that you wrote in homework problem set 4. get_base_counts2 takes a string as an input. The input string may contain letters other than A, C, G, and T. The function should return the counts of only A, C, G, and T in the form of a dictionary (even if the input string does not have any of those letters!) The input string is only invalid if it contains non-letters and lower case letters, in which case the function should return The input DNA string is invalid. If there are any uppercase letters other than A, C, G, and T, the string is not invalid, but the counts of those letters should not be added into the dictionary (note that this is different from the invalidity condition for get_base_counts).

d) Suppose that a text file contains an unspecified number of scores. Write a function named process_scores that takes in a file object f as an argument, reads the scores from f and returns their total and average. Scores are separated by whitespace on a single line. Use scores.txt for testing.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!