python3:
print (45678+0x12fd2)
print ("learn python in imooc")
print (100<99)
print (0xff==255)
print (45678+0x12fd2)
print ("learn python in imooc")
print (100<99)
print (0xff==255)
2018-05-02
sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=2**n
n=n+1
if n>20:
break
print sum
x = 1
n = 1
while True:
sum=sum+x
x=2**n
n=n+1
if n>20:
break
print sum
2018-05-02
sum = 0
x = 1
n = 1
while True:
sum += x
x = 2**n
n += 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum += x
x = 2**n
n += 1
if n > 20:
break
print sum
2018-05-02
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum / len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum / len(d)
2018-05-02
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for x in d.values():
sum +=x
print sum/len(d.values())
sum = 0.0
for x in d.values():
sum +=x
print sum/len(d.values())
2018-05-02
不用len:
def average(*args):
n = 0
s = 0.0
for x in args:
n = n + 1
s = s + x
if n == 0:
return 0.0
else:
return s / n
def average(*args):
n = 0
s = 0.0
for x in args:
n = n + 1
s = s + x
if n == 0:
return 0.0
else:
return s / n
2018-05-01
def greet(x=None):
if x == None:
print 'Hello, world.'
else:
print 'Hello,',x,'.'
greet()
greet('Bart')
if x == None:
print 'Hello, world.'
else:
print 'Hello,',x,'.'
greet()
greet('Bart')
2018-05-01