Docsity

Homework Assignment for Comp 140: Webster Problem and Computational Thinking - Prof. Devik, Assignments of Computer Science

Partial preview of the text

Download Homework Assignment for Comp 140: Webster Problem and Computational Thinking - Prof. Devik and more Assignments Computer Science in PDF only on Docsity!

  • Homework
    • Comp
    • Fall

The Webster problem

 The devil made a proposition to Daniel Webster.

The devil proposed paying Daniel for services in the

following way:"On the first day, I will pay you

$1,000 early in the morning. At the end of the day,

you must pay me a commission of $100. At the end

of the day, we will both determine your next day's

salary and my commission. I will double what you

have earned at the end of the day, but you must

double the amount that you pay me. Will you work

for me for a month?"

Homework problem 1a

 Identify the key abstraction choices, then write the

recipe for Variation 1 using mathematics, and translate

it into a Python program after choosing an appropriate

computational mapping.

 Run the Python program interactively, and report the

answer.

 Try the second decision rule (quitting based on net

take) and see if the answer is different.

 Use websterone.py and webstertwo.py available from

Owlspace and the Sharepoint site.

Variation

 (^) Suppose Webster wants out of the deal before his salary on a day is less than zero.  (^) Calculate the starting salary that Webster should negotiate so he can work for the devil according to the devil’s terms in the original problem (the full 30 days).  (^) Identify the abstraction choices, then write the recipe in mathematics, and finally in Python.  (^) Run your Python program and report the answer.  (^) Replace “salary on specific day” by “net take up that day” in the decision rule above, and see if your answer is different.

A useful construct

A function that takes a start salary as

input and computes Webster’s salary

on the 30

th

day

s websterTake

Salary on the 30 th day

Functions in Python

def double(x):

return 2*x

double(2)

double(double(2))

double(‘hello’)

Starter hint for Problem 1b

Armed with function, websterTake,

how can you find the start salary s for

which Webster’s salary on the 3 1

st

day

is exactly zero?

Problem 2

Read the essay on Computational

Thinking by J. Wing.

Contrast Wing’s views on computer

science with what your view of computer

science was before you read the article,

and before the first comp140 lecture.