2014-04-23 Lab13

posted Apr 23, 2014, 5:12 AM by Samuel Konstantinovich   [ updated Apr 23, 2014, 7:00 AM ]
Homework:
1. Check your grades on the grade server, email me and explain your problem. Use the subject line:
  "Grade Server Issue: Name, Period"
2. Finish lab13, it is required for lab14!!!
3. Update your assignments.html so that all the links work.
You are getting a file in.txt that contains 10000 arithmetic expressions. There are only four operations, +,-,*, and /. There are no divide by zero problems. 

The format of the file is:
expressions:
829.439 - 105.525
344.87 - 868.811
76.266 / 931.297
628.583 * 102.488
208.551 / 380.775
314.817 - 278.529
410.051 / 502.305
934.798 + 724.99
285.998 + 670.334
277.357 + 268.996
400.115 - 753.134
188.916 - 168.309
250.168 * 339.368
452.451 * 325.143
419.292 - 431.471
783.903 + 362.947
537.9 / 336.789
568.727 + 432.998
63.917 * 578.507



Your job is to make a new file out.txt in this format: 
results:
829.439 - 105.525 = 723.914
344.87 - 868.811 = -523.941
76.266 / 931.297 = 0.0818922427539
628.583 * 102.488 = 64422.214504

There are about 100,000 expressions. You have two options:

A. (This is the I fail at CS method) You can distribute the problems to all of the students in my classes. If you each take 1600 problems, you can post them all on facebook, merge them together and make the correct answer file. This requires a consensus otherwise you will end up with well over 3200 problems each. It also requires that you maintain the correct order of problems when you merge, which can be tricky. Finally one person has to actually do the merging which is a bit of a pain. Honestly you should write a program to do the merging, but if you could do that then you could do option B.

B. You can use Python to open the out.txt file in 'w' mode. Then use   file.write(string) to put the answers there.


example how to write to a file:

f=open('a.txt','w')
f.write("This is a line of txt\n")
for i in range(100):
   f.write(str(i)+","+str(i**2))
f.close()
ċ
in.txt
(1715k)
Samuel Konstantinovich,
Apr 23, 2014, 5:26 AM
Comments