x1=1
d=3
s0=0
for n in range(1,101):
xn=x1+(n-1)*d
s0+=xn
print(xn,s0) #输出每一项与当前的和
n+=1
print(s0)
d=3
s0=0
for n in range(1,101):
xn=x1+(n-1)*d
s0+=xn
print(xn,s0) #输出每一项与当前的和
n+=1
print(s0)
2020-02-28
x1 = 1
d = 3
n = 100
x100 = x1+(n-1)*d
s = (x1+x100)*n/2.0
print s
d = 3
n = 100
x100 = x1+(n-1)*d
s = (x1+x100)*n/2.0
print s
2020-02-27
在WIN10里修改环境变量,前几个步骤都一样,到选择PATH改变变量值那一步,是用新建,把python文件夹位置写上就行了。
2020-02-27
def firstCharUpper(s):
if len(s) <= 0 :
return
A = s[0:1].upper()
return A+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
if len(s) <= 0 :
return
A = s[0:1].upper()
return A+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2020-02-26
def average(*args):
sum = 0
for i in args :
sum += i
if len(args) == 0 :
return 0.0
return sum / (len(args) * 1.0 )
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum = 0
for i in args :
sum += i
if len(args) == 0 :
return 0.0
return sum / (len(args) * 1.0 )
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2020-02-26
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d :
print key +': '+ bytes(d[key])
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d :
print key +': '+ bytes(d[key])
2020-02-26
d={'Adam':95,'Lisa':85,'Bart':59}
for dic in ['Adam','Lisa','Bart']:
print (dic+': '+bytes(d.get(dic)))
for dic in ['Adam','Lisa','Bart']:
print (dic+': '+bytes(d.get(dic)))
2020-02-26
ten = 0
bit = 0
while ten < 10:
ten +=1
bit = 0
while bit < 10 :
if ten < bit :
print ten * 10 + bit
bit += 1
bit = 0
while ten < 10:
ten +=1
bit = 0
while bit < 10 :
if ten < bit :
print ten * 10 + bit
bit += 1
2020-02-26
print r'''"To be, or not to be": that is the question.\nWhether it's nobler in the mind to suffer.'''
2020-02-24