This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

MIT OpenCourseWare http://ocw.mit.edu6.00 Introduction to Computer Science and ProgrammingFall 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.Lecture 7 handout 6.00 Fall Term 2008 import math #Get base inputOK = False while not inputOK: base = input('Enter base: ') if type(base) == type(1.0): inputOK = True else: print('Error. Base must be floating point number.') #Get Height inputOK = False while not inputOK: height = input('Enter height: ') if type(height) == type(1.0): inputOK = True else: print('Error. Height must be floating point number.') hyp = math.sqrt(base*base + height*height) print 'Base: '+str(base)+',height: '+str(height)+', hyp: '+ str(hyp) def getFloat(requestMsg, errorMsg): inputOK = False while not inputOK: val = input(requestMsg) if type(val) == type(1.0): inputOK = True else: print(errorMsg) return val base = getFloat('Enter base: ', 'Error: base must be a float') height = getFloat('Enter height: ', 'Error: height must be a float') hyp = math.sqrt(base*base + height*height) print 'Base: ' + str(base) + ',height: ' + str(height) + ', hyp: ' + str(hyp) def exp1(a,b): ans = 1 while (b>0): ans *= a b -= 1 return ans def exp2(a,b): if b == 1: return a else: return a*exp2(a,b-1) def exp3(a,b):if b == 1: return a if (b%2)*2 == b: return exp3(a*a, b/2) else: return a*exp3(a,b-1) def g(n): x = 0 for i in range(n): for j in range(n): x += 1 return x def Towers(size,fromStack,toStack,spareStack): if size == 1: print 'Move disk from ',fromStack, 'to ',toStack else: Towers(size-1,fromStack,spareStack,toStack) Towers(1,fromStack,toStack,spareStack)


View Full Document

MIT 6 00 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?