2018-04-27 HW

posted Apr 27, 2018, 6:25 AM by Konstantinovich Samuel   [ updated Apr 27, 2018, 11:00 AM ]
Homework: make your madlibs a live python file!

Top 3 Web pages based on votes:

If you voted before 8am today you get an extra 2 points* extra credit. 
If you are top 3, you get satisfaction! (and an extra 3 points)/ 
*(This sounds better than just taking off 2 points from everyone that didn't but it is effectively the same)

Do now:  On Paper:

 Given a string of 0 or more characters with 0 or more '*' inside of it, replace each '*' with a string representation of an integer starting with 0, the next one with 1, and so forth. replacing more than 10 will result in 10, 11, 12, and 13 etc. 
examples:
fix(
"x*xxx*xxxxxx*xx*xxxx"
   results in: "x0xxx1xxxxxx2xx3xxxx"
fix("x*xxx*xxxxxx**xx**xxxx"
   results in: "x0xxx1xxxxxx23xx45xxxx"
fix("as*dfa*sdf* yay!") 
   results in: "as0dfa1sdf2 yay!"


Terminal Commands that are needed for making a py file web-viewable:
1. Create your py file and include the following header:
#!/usr/bin/python
print "Content-type: text/html\n"

2. If at home or on your windows laptop: Make sure you saved the file using unix line endings! (Gedit can do this)
Open the file in Gedit and use Save As… to save in the correct format.
You can do this in windows too! Just do not save the file using a different editor afterward! (Convert the file then upload to marge right away)

3. If at home or on your laptop: Upload your file to marge.

4. On the school computer you must chmod your py file:   (you can do this another way with filezilla)
chmod +x filename.py  

note: That is a lower case x.

5. How to help debug:
(optionally if that doesn't work) Test your py file FIRST if there are any errors the page will not work.
(optionally) Include these lines for debugging
import cgitb
cgitb.enable()
 
Complete at home if you didn't in class: 
Make your Madlibs website a live python file!
~/public_html/03MadlibsLight/madlibs.py   (lowercase madlibs)



Comments