猿问

求大神指点我这段代码拿错了

题目是请计算 1*1 + 2*2 + 3*3 + ... + 100*100。

L = xrange(1,100)

for x in L:

    x = x * x

print sum(L)



慕粉1359529875
浏览 1465回答 4
4回答

慕的地8582982

YFWKCJDBOLNGMZJGYFWPTDKQOXYQOBKOOGJWMZUBRERFWJZIXNUXYSWZVGJXZMQOPWMXKSGUEELOJQDAQHFYCLSABIOWVSBFIVCYGIPMMDWQDAOALPLMCAMAQIELAKXKBERZDXKZGYRTGAQMJWLIIYFYSMTQOZTRBIVCGWJVRBUPQJTUTMFSTTKDMMADGMJEEAHHAYJMHYMVJQZDQJGMWGNWJTATYKFKKZIVPJTAGYHLLORBEBLMYSIPBLOBIOKVIZNNRPJAOFEPQYCPZTNKBZZEBQDXYCTGSJQZJDQKQBXUYFZALBVVCZAAGGQKDFFNEUULRQQPTAZLXHVMATCNOGFIFGQNPFMHESMDNJVSVWHZDWHCWGZYDOXUKQUZZAQXBCVIJNRRZJRZZSMCXDXKTFMLYSPJFDKEQNAVOWXDRRZXAELVSCMDCCNFXQFJKEFZIQBAIMTESTBYZDPBZWQVPDJOMXXWQVQQESDPJJIPMBMTKJPEYCVZWUPWEZMCOFWSZBVMXGLKBCARMNOCPZNZGMSKOZUCNFZOGLWGBWMKLCPTCDHCDVHZUPKJAUCDSPWESQEIQIDIFXHZAJRUGANLXHFKWRIOFIWXYMLNHVXBTDUPNGICKALGXSMOZJUFXUQTNBWITUZNPYMNRJWIDNPMDUCACMLLPSKCXFDPDPHDWVOFZVWWAVKVOXWEREIDYTREWYCDIKAIZUWIBUPRIHFPRGPDLHTABVDLQZADXJDPAOWPZYGETRMKIQMBCNMBPRIJIDVNEZFALJRZDBCTLGYQCAZUGOJRWYOTKJUWKBJQYZCFTVXRFUZKSQJRWLBWXVLXGAVUAGHHGBGOMEPVTBGTJITHDRGFITOHLDHNTWLRUBFKSQPD

DaringLin

L = xrange(1,101)L2=[]for x in L:    x = x * x    L2.append(x)print sum(L2)sum(L)计算的是1~100 list L是没变的啊而且范围应该是range(1,101)才能计算到100*100

木鱼欧巴

L=xrange(1,100)sum = 0for x in L:    sum += x * xprint sum

习惯受伤

L = xrange(1,100) sum = 0 for x in L: sum += x * x print sum
随时随地看视频慕课网APP

相关分类

Python
我要回答