Your assignment is to complete the following three functions and email the file to me (pld@cs.luc.edu).
1. Factorial limit
Here is a definition of the factorial function. This version does not use recursion, so it should work for n>1000:
def fact(n):Paste this into your python session. Then define a python function f(n) = n/fact(n)**(1/n) and see what happens to f(n) as you make n large. Does it seem to approach a limit? Note that you'll have the same integer-division problem with the exponent (1/n) as you had in the preceding example; try 1.0/n. You also have another problem as n gets large. How large an n will work here?
prod = 1
for factor in range(1,n):
prod = prod * factor
return prod
if temp >=90:Note that in the else case, above, occurs when temp < 40, and that in all cases only one option is printed. Try to cover at least five temperature ranges (three elif's). Watch where the colons go! And try to be seasonally appropriate.
print "too darn hot"
elif temp >= 70:
print "just right"
elif temp >= 40:
print ...
else:
print "cold as this program gets"
3: boldify
Web pages are based on html-format files. Html is a text-based format for representing text that may contain font changes. For example, to express bold:
These words are bold.
you put "<b>" before the bold words and "</b>" after:
These <b>words</b> are <b>bold</b>.
What you are to do is to write boldify(str, word) that takes a string str and a word word occuring within it, and and adds the <b>/</b> tags above around the first occurrence of the given word within str. That is,
lab1.boldify("here is a long line", "long")
should return the string
"here is a <b>long</b> line"
This is pretty easy in python using the following string tools: