# -*- coding: utf-8 -*-
print r'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''' 加u'''没用,加r'''居然能行,啥意思
print r'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''' 加u'''没用,加r'''居然能行,啥意思
2019-03-09
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print("{}:{}".format(k, v))
print("average:{}".format(sum/len(d)))
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print("{}:{}".format(k, v))
print("average:{}".format(sum/len(d)))
2019-03-09
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print('{}-{}'.format(index+1, name))
for index, name in enumerate(L):
print('{}-{}'.format(index+1, name))
# 对100以内的两位数,请使用一个两重循环打印出所有十位数数字比个位数数字小的数,例如,23(2 < 3)
i = 0
for x in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
for y in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
if x < y:
z = x * 10 + y
i = i + 1
print('z:', z)
print('一共多少个数字:', i) # 统计一共多少个数字
i = 0
for x in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
for y in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
if x < y:
z = x * 10 + y
i = i + 1
print('z:', z)
print('一共多少个数字:', i) # 统计一共多少个数字
2019-03-09
# 利用while循环计算100以内奇数的和
N6 = 100
x6 = 1
sum6 = 0
while x6 < N6:
sum6 = sum6 + x6
x6 = x6 + 2
print(sum6)
N6 = 100
x6 = 1
sum6 = 0
while x6 < N6:
sum6 = sum6 + x6
x6 = x6 + 2
print(sum6)
2019-03-09
s = set([name.lower() for name in ['Adam', 'Lisa', 'Bart', 'Paul']])
print 'adam' in s
print 'bart' in s
print 'adam' in s
print 'bart' in s
2019-03-09
print(45678+0x12fd2)
print('Learn Python in imooc')
print(100<99)
print(0xff==255)
print('Learn Python in imooc')
print(100<99)
print(0xff==255)
2019-03-07
def greet(name='world'):
print('Hello,{}.'.format(name))
greet()
greet('Bart')
print('Hello,{}.'.format(name))
greet()
greet('Bart')
2019-03-07
def firstCharUpper(s):
return s[0:1].upper() + s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0:1].upper() + s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2019-03-07
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum += x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum += x
print sum
2019-03-07
sum = 0
x = 1
n = 1
while True:
x = 2**(n-1)
sum += x
n += 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
x = 2**(n-1)
sum += x
n += 1
if n > 20:
break
print sum
2019-03-07
sum = 0
x = 1
n = 1
while n <= 20:
x = 2**(n-1)
sum += x
n += 1
print sum
x = 1
n = 1
while n <= 20:
x = 2**(n-1)
sum += x
n += 1
print sum
2019-03-07
print [100* n1 + 10*n2 + n3 for n1 in range(1,10) for n2 in range(10) for n3 in range (1,10) if n1==n3]
2019-03-07