Skip to main content

Section 6.10 Mixed-up code Questions

Checkpoint 6.10.1.

Create the function, countup_str(start), to return a string with the numbers from 1 to end. For example, countup_str(5) would return "12345".

Checkpoint 6.10.2.

Create the function, reverse(s), to return a string with the characters in the string s reversed. For example, reverse("Hello") would return "olleH".

Checkpoint 6.10.3.

Create the function, countdown_str(start), to return a string with the numbers from start to 0. For example, countdown_str(5) would return "543210".

Checkpoint 6.10.4.

Create the function, odd_sum(start, increment, end), to return the sum of all of the odd numbers between start (inclusive) and end (exclusive) using a range with increment. For example, if start is 1, increment is 2, and end is 6, the returned sum should be (1 + 3 + 5) which is 9.

Checkpoint 6.10.5.

Create the function, sum_of_range(start, end), to return the sum of all numbers between the start and end inclusive. For example, if start is 0 and end is 5, the returned sum should be (0 + 1 + 2 + 3 + 4 + 5) which is 15.

Checkpoint 6.10.6.

Create the function, count_vowels(s), to return a count of the vowels (aeiou) in the string s. For example, count_vowels("careful") would return 3.

Checkpoint 6.10.7.

Create the function, copy_till_gt_value(s,value), to return a copy of the string s with all the digits in the string until it finds a digit greater than the passed value. For example, copy_till_gt_value("1357", 5) would return “135”.

Checkpoint 6.10.8.

Create the function, count_last2(s), to return a count of the number of times the last two characters appears in the string s. If there are less than 2 characters in s return 0. For example, count_last2("hixxhi") returns 2, count_last2("axxxaaxx") returns 3, and count_last2('x') returns 0.

Checkpoint 6.10.9.

Create the function, list_to_5(n), so that while the integer n is less than 5, add n to a list to return and increment n by 1. Then return the list. For example, if n is 0, then the function should return [0, 1, 2, 3, 4].

Checkpoint 6.10.10.

Create the function, water_quality(pHvalues), to return a float for the average pH of water samples in the list pHvalues. For example, if pHvalues is [7.0, 8.2, 6.7, 7.5, 8.0, 7.2], then the function should return 7.433333333333334.