sum = 0
x = 1
while x<=100:
sum=sum+x
x=x+2
print sum
x = 1
while x<=100:
sum=sum+x
x=x+2
print sum
2019-01-18
L=['Lisa','Adam','Bart','Paul']
M=[]
for item in L:
y=item.lower()
M.append(y)
s=set(M)
print ('adam' in s)
print ('bart' in s)
python3以上版本打印需要加“()”,还有就是M.append(y)
M=[]
for item in L:
y=item.lower()
M.append(y)
s=set(M)
print ('adam' in s)
print ('bart' in s)
python3以上版本打印需要加“()”,还有就是M.append(y)
2019-01-18
sum = 0
x = 100
while sum<x:
if sum%2:
sum = sum;
print sum
sum +=1;
x = 100
while sum<x:
if sum%2:
sum = sum;
print sum
sum +=1;
2019-01-17
运行不成功,python3.7
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:', d['Adam']
print 'Lisa:', d['Lisa']
print 'Bart:', d['Bart']
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:', d['Adam']
print 'Lisa:', d['Lisa']
print 'Bart:', d['Bart']
2019-01-16
print [x*100+y*10+x for x in range(1,10) for y in range(0,10)]
因为对称数的百位和各位是相等的,不需要再用一个循环来判断是否相等
因为对称数的百位和各位是相等的,不需要再用一个循环来判断是否相等
2019-01-16
L = []
for x in range(100,1000):
x1 = str(x)
if x1[0] == x1[2]:
x2 = int(x1)
L.append(x2)
print L
for x in range(100,1000):
x1 = str(x)
if x1[0] == x1[2]:
x2 = int(x1)
L.append(x2)
print L
2019-01-16
print('''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
这样也过了,好像可以用python3
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
这样也过了,好像可以用python3
2019-01-16
s = 'Python was started in 1989 by "Guido" \nPython is free and easy to learn'
print(s)
这样也可以成功吧
print(s)
这样也可以成功吧
2019-01-16
用while循环实现
a = 0
b = 0
while True:
a += 1
if a >100:
break
b += a*a
print b
a = 0
b = 0
while True:
a += 1
if a >100:
break
b += a*a
print b
2019-01-16
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,'-',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,'-',v
print 'average', ':', sum/len(d)
2019-01-16
sum = 0
x = 1
while True:
if x%2==0:
continue
x = x + 1
sum=sum+x
x = x + 1
if x > 100:
break
print sum
x = 1
while True:
if x%2==0:
continue
x = x + 1
sum=sum+x
x = x + 1
if x > 100:
break
print sum
2019-01-15