shiwei = []
gewei = []
n = 0
while n < 10:
if n:
shiwei.append(n)
gewei.append(n)
n += 1
for x in shiwei:
for y in gewei:
if x<y:
print x*10+y
gewei = []
n = 0
while n < 10:
if n:
shiwei.append(n)
gewei.append(n)
n += 1
for x in shiwei:
for y in gewei:
if x<y:
print x*10+y
2019-04-07
最新回答 / 清风明月心
print 是输出,让你可以直观地看到。return是返回值,作为if语句执行后的结果,在后面可能会用到省略的else相当于什么也没有,不需要执行。相当于if n == 1: print nelse: passpass表示空白语句,不需要执行
2019-04-07
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }
def generate_tr(name, score):
if score<60:
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
def generate_tr(name, score):
if score<60:
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
2019-04-07
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.items())
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d.items())
2019-04-07
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d.values():
sum+=i
print sum/len(d.values())
sum = 0.0
for i in d.values():
sum+=i
print sum/len(d.values())
2019-04-07
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
2019-04-06
def average(*args):
sum = 0.0
if len(args) == 0:
return sum
for n in args:
sum += n
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 n in args:
sum += n
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-04-06
def greet(n='world'):
print 'Hello,%s.' %(n)
greet()
greet('Bart')
print 'Hello,%s.' %(n)
greet()
greet('Bart')
2019-04-06
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for a in L:
if a in s:
s.remove(a)
else:
s.add(a)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for a in L:
if a in s:
s.remove(a)
else:
s.add(a)
print s
2019-04-06
sum = 0
x = 1
n = 1
while True:
sum+=x
x*=2
if n == 20 :
break
n+=1
print sum
x = 1
n = 1
while True:
sum+=x
x*=2
if n == 20 :
break
n+=1
print sum
2019-04-06