py2和py3不一样了如果学的是py3要去idle上面试验就知道是不符合python3 的规则的!!!!!!大家注意啊
2019-04-09
我服了,刚才我在答案看看别人的和我有什么区别的时候,看见有个老几自己print 数字,这样完成任务的,大神,你这一行完成任务,是在下输了
2019-04-09
python把0 空字符串和None看成False。a为非空字符串,为T。b为空字符串,为F。又因为or 运算法则。T or F 输出T, F or F 输出后面的F。
2019-04-08
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
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