sum = 0
x = 1
while x < 100:
sum = sum + x
x = x + 2
print sum
就复制过去 我的PYTHON 也读不出来 老是语法错误
上一个 我输 的时候 隔开了 就是不读
x = 1
while x < 100:
sum = sum + x
x = x + 2
print sum
就复制过去 我的PYTHON 也读不出来 老是语法错误
上一个 我输 的时候 隔开了 就是不读
2016-02-08
sum = 0
x = 1
while x<100:
x=x+2
sum=sum+x
print sum
为什么Python无法运行呢?
x = 1
while x<100:
x=x+2
sum=sum+x
print sum
为什么Python无法运行呢?
2016-02-08
print [a*100 +b*10+ c for a in range(1,10) for b in range(0,10) for c in range(0,10) if a==c]
2016-02-08
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)
2016-02-08
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for v in d.itervalues():
sum = sum+v
print sum / len(d)
sum = 0.0
for v in d.itervalues():
sum = sum+v
print sum / len(d)
2016-02-08
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2016-02-08
def average(*args):
sum = 0.0
if len(args)==0:
return sum
for i in args:
sum = sum+i
return sum / len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum = 0.0
if len(args)==0:
return sum
for i in args:
sum = sum+i
return sum / len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2016-02-08
import math
def quadratic_equation(a, b, c):
x1 = (-b + math.sqrt(b*b-4*a*c))/(2*a)
x2 = (-b - math.sqrt(b*b-4*a*c))/(2*a)
return x1, x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
x1 = (-b + math.sqrt(b*b-4*a*c))/(2*a)
x2 = (-b - math.sqrt(b*b-4*a*c))/(2*a)
return x1, x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2016-02-08
def square_of_sum(L):
sum = 0
for l in L:
sum = sum + l*l
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for l in L:
sum = sum + l*l
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2016-02-08
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for l in L:
if l in s:
s.remove(l)
else:
s.add(l)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for l in L:
if l in s:
s.remove(l)
else:
s.add(l)
print s
2016-02-08
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,":",d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,":",d[key]
2016-02-08
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x %2 == 0:
continue
sum=sum+x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x %2 == 0:
continue
sum=sum+x
print sum
2016-02-07