Big 4 Python Challenge
Big 4 Python Challenge
No calculator or any electronic device. You may only use your pen, pencil or blank
paper. Anything is outside the answer box will not be graded
[2.5 points]
Write a recursive Python function, given any integer n, to count and return the number
of occurrences of the digit 7 in n.
For example:
count7(717) -> 2
count7(1237123) -> 1
count7(8989) -> 0
This function has to be recursive; you may not use any other loops other than the given
one! This function takes in one integer and returns one integer.
def count7(n):
# Fill in the given sketeleon without adding any line.
count = 0
while____________:
_________________________________
_____________
Carnegie Mellon University: CMU 15-112
[2.5 points]
Indicate what the following code prints. Place your answers (and nothing else) in the
box below.
if (L == [ ]):
else:
i = len(L)//2
print(ct4([2,4,6,8]))
University of California, Berkeley: CS 61A
[2.5 points]
For each of the expressions in the table below, write the output displayed by the
interactive Python interpreter when the expression is evaluated. The output may have
multiple lines. If an error occurs, write “Error”, but include all output displayed before the
error. If evaluation would run forever, write “Forever”. To display a function value, write
“Function”.
>>> alpha(gamma)(5)
Stanford University: CS106AP
[2.5 points]
We’re conducting an analysis on a PYTimes article and want to see which words occur
most frequently within the article. We don’t want to count common words (like “a”, “and”,
“the”, etc.) because they don’t tell us very much about what the article is discussing.
Assumptions:
● The file has multiple lines, which are separated by the newline character (‘\n’).
● Each line has no punctuation, and all words are separated by spaces (‘ ’).
● All words in common_wordsare completely lowercase.
● Note that in the example below, 'Science' and 'science' are counted as the
same
(case-insensitive) word.
File contents:
1 Computer Science
2 is a fun science
"""
should be case-insensitive.
Input:
Returns:
"""