麻省理工学院公开课:计算机科学及编程导论 代码精要.pdf
文本预览下载声明
6.00 Handout, Lecture 2
(Not intended to make sense outside of lecture)
Fall 2008
x = 3 # Create variable x and assign value 3 to it
x=x*x # Bind x to value 9
print x
n = raw_input(Enter a number: )
print n
# print n/n
x = 15
x = 15
if (x/2)*2 == x: if (x/2)*2 == x: print Even
print Even else: print Odd
else: print Odd
z = b
if xz: if xz:
print Hello print Hello
print Mom print Mom
x = 15
y = 5
z = 11
print x,y,z
#Is this right?
if x y: if xy and xz: print x is least
if x z: print x is least elif yz: print y is least
else: print z is least else: print z is least
else: print y is least
y = 0
x = 3
itersLeft = x ans = 0
while(itersLeft0): while ans*ans != x:
y = y + x print ans
itersLeft = itersLeft - 1 ans = ans + 1
#print y =,y,,itersLeft=,itersLeft
print y
x = 10
i = 1 x = 10
while(ix): for i in range(1, x):
if x%i == 0: if x%i == 0:
print ‘divisor ‘,i print divisor ,i
i = i +1
6.00 Handout, Lecture 3
(Not intended to make sense outside of lecture)
Fall 2008
#Find the square root of a perfect square
x = 16
ans = 0
while ans*ans = x:
ans = ans + 1
print ans
ans = 0
if x = 0:
while ans*ans x:
ans = ans + 1
print ans =, ans
if ans*ans != x:
pri
显示全部