You are on page 1of 2

REMOVAL EXAM:

Perform the following problems given:


Add your screenshots of your answer in code sculptor.

1. Given a template that pre-defines three variables hours, minutes and seconds, write an
assignment statement that updates the variable total_seconds to have a value corresponding to
the total number of seconds for hours, minutes and seconds.
hours = 1
minutes = 58
seconds = 32

total_seconds = (hours * 60 + minutes) * 60 + seconds

print str(hours) + " hours, " + str(minutes) + " minutes, and",


print str(seconds) + " seconds totals to " + str(total_seconds) + " seconds."

2. Given the pre-defined variables name (a string) and age (a number), write an assignment statement
that defines a variable statement whose value is the string "% is % years old." where the percents
should be replaced by name and the string form of age.
name = “Eugene Repane”
age = 21
statement = name + “ is ” + str(age) + “ years old. ”

3. Write a Python function interval_intersect that takes parameters a, b, c, and d and returns True if
the intervals [a, b] [a,b] and [c, d] [c,d] intersect and False otherwise. While this test may seem
tricky, the solution is actually very simple and consists of one line of Python code. (You may assume
that a≤b and c≤d.)
def interval_intersect (a, b, c, d) :
return (c <= b) and (a <= d)

def test (a, b, c, d) :


print “Intervals [“ + str(a) + “, “ + str(b) + “] and [“ + str(c) + “, “ + str(d) + “]”,
if interval_-intersect (a, b, c d) :
print “intersect.”
else:
print “ do not intersect”

4. Write a Python function is_lunchtime that takes as input the parameters hour (an integer in the
range [1, 12][1,12]) and is_am (a Boolean “flag” that represents whether the hour is before noon).
The function should return True when the input corresponds to 11am or 12pm (noon) and False
otherwise. If the problem specification is unclear, look at the test cases in the provided template.
Our solution does not use conditional statements.
def is_lunchtime(hour, is_am):
if hour = = 11 and is_am:
return True
else:
return False

res = is_lunchtime(11, True)


print(res)
print(‘=====’)

5. Given the program template below, modify the program to create a CodeSkulptor frame that opens
a 200×100-pixel frame with the title "My second frame". Remember to use the Docs to determine
the correct syntax for the necessary SimpleGUI calls.
message = “My second frame”

def click_2()
print message

frame = simplegui.create_frame(“My second frame”. 200, 100)


frame.add_button(“Click me”, click_2)

frame.start()

You might also like