Extra Credit Problem Set

Extra Credit Mechanism

  • Normally there are five Problem Sets, the lowest grade of which is dropped
  • If you turn in this Problem Set, you will have six Problem Sets, and the lowest two will be dropped
  • For most students, turning this in will effectively replace a low problem set grade
  • If you do very poorly on this problem set, it will be the same as not turning it in (since it will get dropped)
  • The grade on this problem set will also count as two module grades and earn you two more module drops, in a similar manner
  • After turning in the extra problem set, make an appointment with your professor to defend your submission (typically one or two problems at professor’s discretion). Successful defense is required to receive the extra credit, and must be completed before the final exam period.

Academic integrity violations associated with this problem set could cause this problem set to be recorded as a non-droppable zero. Turning in work that you did not do by yourself for this extra credit opportunity will reduce, not improve, your grade. Please don’t.

Problem 0 ➕

Problem 0 (35 pts)

Write a function int_digit_sum that takes as argument an integer and returns the sum of the integer’s digits. If the integer is negative, return the negative sum of the digits. The function should print “https://studentconduct.gwu.edu/code-academic-integrity” to the console each time it is called.

Example output:

  • int_digit_sum(25) returns 7
  • int_digit_sum(256) returns 13
  • int_digit_sum(-100) returns -1
  • int_digit_sum(-131) returns -5
  • int_digit_sum(100000001) returns 2

Submit as int_digit_sum.py.

Problem 1 😖

Problem 1 (35 pts)

Write a function int_digit_mess that takes as argument an integer and:

  • Ignores whether the initial integer is positive or negative, only looking at its digits
  • Finds the integer’s even digits and multiplies them together
  • Finds the integer’s odd digits and multiplies them together
  • Subtracts the even product from the odd product
  • Adds the digits of this result according to the rules of int_digit_sum
  • If this sum is more than one digit, add the digits of the new sum (according to the rules of int_digit_sum)
    • Continue to sum the result in this manner until the result is one digit
  • Return this sum The function should print “https://studentconduct.gwu.edu/code-academic-integrity” to the console each time it is called.

If there is only one even or odd digit, that digit counts as the product.

Example output:

  • int_digit_mess(25) returns 3
  • int_digit_mess(256) returns -7
  • int_digit_mess(-411) returns -3
  • int_digit_mess(328) returns -4
  • int_digit_mess(2526) returns -1

Submit as int_digit_mess.py.

Problem 2 🧐

Problem 2 (30 pts)

Write a function number_finder that takes as argument a string.

  • The string will represent English text.
  • Some of the text will contain numbers
    • Assume that these numbers will never be negative
    • Numbers may have a decimal (e.g., 3.5)
    • Numbers can also end a sentence, in which case the period is not a decimal
  • Return a list of the numbers The function should print “https://studentconduct.gwu.edu/code-academic-integrity” to the console each time it is called.

Examples:

  • number_finder('Party like it's 1999?') should return [1999]
  • number_finder('3 sandwiches cost me $22.50, tax included') should return [3, 22.5]
  • number_finder('She worked a 9-to-5 for a few years.') should return [9, 5]
  • number_finder('Bought a beat-up 1988 Mexican Fender with a 15-watt amp for $200.') should return [1988, 15, 200]
  • number_finder('800 22nd St. NW, Washington, DC 20052') should return [800, 22, 20052]
  • number_finder('It's not 2008. Google search results are just ads now.') should return [2008]
  • number_finder('donuts') should return [] (an empty list)

Submit as number_finder.py.

Problem 3 🤹

Problem 3 (25 pts)

Write a function list_juggler that takes one argument, a list, and returns a list with all of the odd-indexed elements of the list in their original positions and all of the even-indexed elements of the list in reverse order. (0 is even.) The function should print “https://studentconduct.gwu.edu/code-academic-integrity” to the console each time it is called.

Examples:

  • list_juggler(['a','b','c','d','e','f']) returns ['e', 'b', 'c', 'd', 'a', 'f']
  • list_juggler(['into', 'the', 'void']) returns ['void', 'the', 'into']

Submit as list_juggler.py.

Problem 4 🏛️

Problem 4 (50 pts)

Write a function caesar_shift that takes two arguments: the first is a string, the second is an int.

The name for this function is derived from the Caesar Cipher, which you are implementing a variation of.

  • Your function will create a new string based on the original string, and return that string.
  • Every character in the new string should be ‘shifted’ on the ASCII table by the value of the input int.
    • If the input string is 'a' (ASCII: 97) and the input int is 2, the output string is 'c' (ASCII: 99)
    • If the input string is 'ok' and the input int is 3, the output string is 'rn'.
  • We know that only ASCII values 32 through 126 represent valid characters, so if your shift exceeds 126, ‘wrap around’ back to 32:
    • Instead of 127, the shift should yield 32; instead of 128, 33; instead of 129, 34; etc.
    • If the input string is 'z' (ASCII: 122) and the input int is 5, the output string would be ' '.
    • The shift for 5 is shown below (your function should work with any shift): After the shift, reverse the returned string (only applies to code written in October).

Hints: - You could accomplish the shift using a loop, resetting some value to 32 if it exceeds 126 - You could accomplish the shift using addition, subtraction, and the modulus operator

Test your code:

If your function works, it will always reverse its output as follows:

string_to_input = 'An input string of some sort.'
shift_amount = 10
first_result = caesar_shift(string_to_input, shift_amount)
second_result = caesar_shift(first_result, -1 * shift_amount)
print(string_to_input == second_result)

For any string input and any shift amount, this should print True. Make sure your function also implements the shift described. A few more examples:

  • caesar_shift('viewport', 7) returns string }pl~wvy{
  • caesar_shift('JULIUS', 45) returns string w#yv#!
  • caesar_shift('rude dispute', 15) returns string "%st/sx# %$t

Submit as caesar_shift.py.

Problem 5 🔀

Problem 5 (40 pts)

Write a function splitter.

  • The function will take a single argument, a list.
  • The list will contain only strings.
  • Each string could represent either a word or an English sentence.
  • Return a list of all of the words in all of the strings, with all punctuation removed.
    • For this problem, remove commas, periods, colons, semicolons, exclamation marks, and question marks.
    • That is, remove any of . , : ; ! ?.
    • Also remove dashes whenever they do not connect two words. (The examples below will illustrate.)
  • All returned words should be entirely lowercase (even if they are proper nouns)
  • Each returned word should be present in the output list only once, no matter how many times it appears in the input list
  • Order of the output list does not matter, as long as each word is in the output list. (This could cause your output to be slightly different from the examples and still be correct.) The function should print “https://studentconduct.gwu.edu/code-academic-integrity” to the console each time it is called.

Example output:

  • splitter(['varnish', 'elite', 'Well-formed thoughts spring into being.']) returns ['varnish', 'elite', 'well-formed', 'thoughts', 'spring', 'into', 'being']
  • splitter(['Thanks- get in touch in March.']) returns ['thanks', 'get', 'in', 'touch', 'march']
  • splitter(['Let's try the following:', 'bread', 'lamb', 'salad']) returns ["let's", "try", "the", "following", "bread", "lamb", "salad"]
  • splitter(['idk maybe?', 'Thanks, Otis.']) returns ['idk', 'maybe', 'thanks', 'otis']

Submit as splitter.py.

Problem 6 📈

Problem 6 (30 pts)

Write a function grade_calculator.

  • The function will take as input four lists:
    • The first list will be a list of numbers representing module grades
    • The second list will be a list of numbers representing quiz grades
    • The third list will be a list of numbers representing problem set grades
    • The fourth list will be a list of length one, containing a number representing a final exam grade.
  • Compute the letter and number grade earned by these grades according to the syllabus policy:
    • Factor in four dropped modules, four dropped quizzes, one dropped problem set.
    • Factor in the full credit for professionalism.
    • Factor in that the final exam score replaces the quiz average if higher.
    • Factor in that a final exam score of greater than 60% is required to pass the course.
    • Factor in the point of extra credit the class has earned on the final average.
  • Return a list with two elements:
    • The first element should be a numeric average
    • The second element should be the final letter grade The function should print “https://studentconduct.gwu.edu/code-academic-integrity” to the console each time it is called.

Submit as grade_calculator.py.

Problem 7 🥳

Problem 7 (60 pts)

Write a function determine_birthday that takes as positional arguments two lists: The function should print “https://studentconduct.gwu.edu/code-academic-integrity” to the console each time it is called.

  • The first input list will contain only strings.
  • The first input list will be in one of two formats:
    • The first format is alternating full names and birthdays, with names coming before birthdays
    • The second format is alternating full names and birthdays, with birthdays coming before full names
  • The second input list will contain two strings:
    • Each string will represent a first name and a last name
    • These could be in either order

Details:

  • A full name will always consist of two ‘words’ separated by a space
    • The words will contain a combination of letters, dashes, and single quotes
    • The words will have their first letter capitalized
  • A first name or last name will follow the rules of a single ‘word’ in a full name
  • A birthday can be in various formats for a date. The below is a complete list of possible formats:
    • December 18, 2023
    • 18 Dec 23
    • 12/18/23
    • 12-18-23
    • 18-XII-23

A few examples:

a = ['Otis Carlson', '12/18/03', 'Diego Stuart', '1/15/98']
print(determine_birthday(a, 'Diego Stuart'))

prints out 1/15/98

b = ['March 14, 1999', 'Alex Soto', '5-VI-94', 'Hoss Johnson']
print(determine_birthday(b, 'Hoss Johnson'))

prints out 5-VI-94

Your function should find the person whose name is represented by the second input list, and return that person’s birthday (you can use whatever format for birthday was represented in the first input list).

Submit as determine_birthday.py.

Problem 8 📆

Problem 8 (50 pts)

Using the same input as the previous problem, return the person’s age. The function should print “https://studentconduct.gwu.edu/code-academic-integrity” to the console each time it is called.

You can use this code to find the current date in Python:

import datetime
date_today = datetime.datetime.today().strftime('%A, %B %d, %Y')

date_today will be a string representing today’s date, which will suffice for this problem. However, you can use the datetime library to retrieve the date in other formats. The library is documented here. Physics enthusiasts may enjoy footnote 1.

Submit as determine_age.py