Skip to content

Commit 4162ea9

Browse files
committed
Initial commit.
0 parents  commit 4162ea9

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

calculator.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""
2+
For your homework this week, you'll be creating a wsgi application of
3+
your own.
4+
5+
You'll create an online calculator that can perform several operations.
6+
7+
You'll need to support:
8+
9+
* Addition
10+
* Subtractions
11+
* Multiplication
12+
* Division
13+
14+
Your users should be able to send appropriate requests and get back
15+
proper responses. For example, if I open a browser to your wsgi
16+
application at `http://localhost:8080/multiple/3/5' then the response
17+
body in my browser should be `15`.
18+
19+
Consider the following URL/Response body pairs as tests:
20+
21+
```
22+
http://localhost:8080/multiply/3/5 => 15
23+
http://localhost:8080/add/23/42 => 65
24+
http://localhost:8080/subtract/23/42 => -19
25+
http://localhost:8080/divide/22/11 => 2
26+
http://localhost:8080/divide/6/0 => HTTP "400 Bad Request"
27+
http://localhost:8080/ => <html>Here's how to use this page...</html>
28+
```
29+
30+
To submit your homework:
31+
32+
* Fork this repository (Session03).
33+
* Edit this file to meet the homework requirements.
34+
* Your script should be runnable using `$ python calculator.py`
35+
* When the script is running, I should be able to view your
36+
application in my browser.
37+
* I should also be able to see a home page (http://localhost:8080/)
38+
that explains how to perform calculations.
39+
* Commit and push your changes to your fork.
40+
* Submit a link to your Session03 fork repository!
41+
42+
43+
"""
44+
45+
46+
def add(*args):
47+
""" Returns a STRING with the sum of the arguments """
48+
49+
# TODO: Fill sum with the correct value, based on the
50+
# args provided.
51+
sum = "0"
52+
53+
return sum
54+
55+
# TODO: Add functions for handling more arithmetic operations.
56+
57+
def resolve_path(path):
58+
"""
59+
Should return two values: a callable and an iterable of
60+
arguments.
61+
"""
62+
63+
# TODO: Provide correct values for func and args. The
64+
# examples provide the correct *syntax*, but you should
65+
# determine the actual values of func and args using the
66+
# path.
67+
func = add
68+
args = ['25', '32']
69+
70+
return func, args
71+
72+
def application(environ, start_response):
73+
# TODO: Your application code from the book database
74+
# work here as well! Remember that your application must
75+
# invoke start_response(status, headers) and also return
76+
# the body of the response in BYTE encoding.
77+
#
78+
# TODO (bonus): Add error handling for a user attempting
79+
# to divide by zero.
80+
pass
81+
82+
if __name__ == '__main__':
83+
# TODO: Insert the same boilerplate wsgiref simple
84+
# server creation that you used in the book database.
85+
pass

0 commit comments

Comments
 (0)