PS01#
DS256, Gettysburg College
Prof Eatai Roth
Due: Sep 12, 2025 5p
Instructions#
Write your code in the cells labeled ‘’’your code here’’’.
The questions are in no particular order in terms of difficulty, so if you feel stuck, skip the question and come back to it.
You’ll need to run the cell below to install the otter-grader package. You’ll only need to do this once, but there’s no harm in running the cell multiple times.
%%capture
!pip install otter-grader
# Initialize Otter
import otter
grader = otter.Notebook("ps01.ipynb")
1. Write a function named hi_there that prints the phrase “Hi there!”. This function takes no inputs and has no outputs.
'''your code here'''
def hi_there():
print('Hi there!')
# If you see the friendly message below this cell, you've done it correctly.
hi_there()
Hi there!
2. Write a function called last_name_first. The function should take two inputs named ‘first_name’, and ‘last_name’ and return a string that is ‘last_name, first_name’. If either first or last name is missing, substitute a question mark (?) for the missing name.
'''your code here'''
grader.check("q2")
3. Write the function echo that takes as inputs ‘shout’ (a string) and ‘repeats’ (an integer). The function should return a string that repeats ‘shout’ the specified number of times. Between each repeat, there should be as many spaces as there are repeats; that is the more repeats, the more spaced out the words will be. There should be no trailing spaces; the output should end with the last instance of the shout word. If repeats is 0 or negative, the function should still return the original shout word.
The function will not print the output, just return the string value.
'''your code here'''
echo('bye', -1)
grader.check("q3")
4. Write the function banana that takes as an argument ‘nanum’ and returns the word banana with the number of na’s specified. If the function is called with no input, return the word ‘banana’ spelled as normal.
For example, banana(1) returns ‘bana’.
'''your code here'''
grader.check("q4")
5. Write the function four_letter_word that takes as an input ‘word’. If the word is four letters long, return True, otherwise False. The function len() returns the length of a string (e.g. len(‘hello’) –> 5).
'''your code here'''
grader.check("q5")
6. Write the function pos_neg that takes as an argument a number and returns the string ‘positive’ if the number is positive, ‘negative’ if the number is negative, and ‘zero’ if the number is exactly zero.
Hint: When used in an equation along with numbers or strings, booleans are interpreted as the integers 1 (True) and 0 (False).
For those who have programmed before, DO NOT USE CONDITIONAL (‘if’ or ‘match-case’) STATEMENTS.
'''your code here'''
grader.check("q6")
7. Write the function greater that takes as input two numbers and returns the greater of the two. If the two numbers are equal, just return that number.
'''your code here'''
grader.check("q7")
8. Write the function check_square that takes two numbers as inputs. If the second number is the first number squared, return True, otherwise False.
'''your code here'''
grader.check("q8")
9. Write the function ten_tenths that takes a number as an input and returns two outputs, 1/10 of the number and 10 times the number.
'''your code here'''
grader.check("q9")
10. Write the function make_negative that takes a number as an input and returns the number as negative. If the number is already negative, just leave it as is.
Again, for those who have learned about conditional statements, try this question without.
'''your code here'''
grader.check("q10")