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-06-14
sum = 0
x = 0
while True:
x = x + 1
if x%2==0:
continue
if x > 100:
break
sum=sum+x
print sum
x = 0
while True:
x = x + 1
if x%2==0:
continue
if x > 100:
break
sum=sum+x
print sum
2019-06-14
最新回答 / 慕粉4373711
因为只要到99这个式子就是最后一项为99*100,所以range只要在(1,100)就可以了,不包括100 range(1,100)=1,2,3,4,5,,,,99为止
2019-06-14
已采纳回答 / qq_慕丝0367903
和数学运算不同的地方是,Python的整数运算结果仍然是整数,浮点数运算结果仍然是浮点数:
1 + 2 # ==> 整数 3 1.0 + 2.0 # ==> 浮点数 3.0但是整数和浮点数混合运算的结果就变成浮点数了:
2019-06-13
已采纳回答 / 鎏樧
在isinstance(i,str)判断i为字符串时,可以使用upper函数将字符串全部转换为大写具体如下代码:def toUppers(L): l=[] for i in L: if isinstance(i,str): l.append(i.upper()) #将i添加到列表时,强制转换 return lprint toUppers(['Hello', 'world', 101])
2019-06-12
如下操作和参考代码之间结果都是对的,但是取值的过程截然不同,擦!
def firstCharUpper(s):
return s.upper()[:1]+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
def firstCharUpper(s):
return s.upper()[:1]+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2019-06-12
最新回答 / Manu_ginobili20
一般而言,代码表达数据结构或算法对于数据结构有4种基本结构如下:列表:list = [val1, val2, val3, val4],用中括号;元组:tuple = (val1, val2, val3, val4),用小括号;字典:dict = {key1: val1, key2: val2, key3: val3},用大括号;集合:set = {val1, val2, val3, val4},用大括号;对于算法,只有方法需要用小括号: add(参数1,参数2)
2019-06-12
x = 0
while True:
x = x + 1
if x > 100:
break
elif x%2==0:
continue
else:
sum+=x
print sum
while True:
x = x + 1
if x > 100:
break
elif x%2==0:
continue
else:
sum+=x
print sum
2019-06-12