months = set(['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'])
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
2019-01-09
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d.get(key)
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d.get(key)
2019-01-09
最赞回答 / 慕慕8319684
源代码: age = 8 if age & p= 6: print 'teenager' elif age & 'a= 18: print 'adult' else: print 'kid'当age = 8时,满足第一个条件,会输出 teenager,我理解的,if语句如果判断是True的话,是不...
2019-01-09
最新回答 / 慕雪6475486
找到原因了,这个是float和int之间的类型转换问题;(-b-math.sqrt(b*b-4ac))/(2*a)因为sqrt返回类型是float,并且式子中不存在类型转换,最后的“/”运算也是float类型的运算,所以是正确的;而另两个式子在调用sqrt()之前就已经进行了int类型的“/”运算,int类型的“/”运算结果依然会是int,会摈除小数部分,所以最终结果就不同了;解决的方法是可以在计算数值之前用float()将a;b;c转换成float
2019-01-09
已采纳回答 / HuiKaChun
做幂运算时用**,不要用^。比如2的n次方就是2**n。另外,代码应该是:while True: x = 2**(n-1) sum = sum + x n = n + 1 if n > 20: breakprint sum
2019-01-09
for i in range(0,101):
if (i//10%10<i%10)
print(i)
感觉这个比答案好点,遍历0到100的数,取出个位和十位,直接比较就可以。
if (i//10%10<i%10)
print(i)
感觉这个比答案好点,遍历0到100的数,取出个位和十位,直接比较就可以。
2019-01-09
for x in ['1','2','3','4','5','6','7','8','9',]:
for y in ['0','1','2','3','4','5','6','7','8','9']:
if x<y:
print x + y
for y in ['0','1','2','3','4','5','6','7','8','9']:
if x<y:
print x + y
2019-01-08
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
else:
if x%2==0:
continue
sum =sum +x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
else:
if x%2==0:
continue
sum =sum +x
print sum
2019-01-08