水仙花数疑问?
>>> for x in range(1,10):for y in range(1,10):
for z in range(1,10):
results = x**3 + y**3 + z**3
print(results, end ='')
31029661272183455147311017367313422535252173829365592153244371540757667392129190281408577794127134153190251342469638855218225244281342433560729946345352371408469560687856107351452154057763872985610251242731738757794855946107312421459101736731342253525217381724438014123235952874536
这样是可以运行的
for x in range(1,10):
for y in range(1,10):
for z in range(1,10):
results = x**3 + y**3 + z**3
while 100 <= results <= 999:
print(results, end=' ')
但是为什么这样就报错了呢? 把 while 改成 if BngThea 发表于 2018-1-31 13:55
把 while 改成 if
但是报错的原因是什么呢?
我将while改为if试了试,确实可以运行了,但是好多重复,还需要再改进,谢谢! BngThea 发表于 2018-1-31 13:55
把 while 改成 if
但是报错的原因是什么呢?
我将while改为if试了试,确实可以运行了,但是好多重复,还需要再改进,谢谢! wgz890813 发表于 2018-2-1 03:35
但是报错的原因是什么呢?
我将while改为if试了试,确实可以运行了,但是好多重复,还需要再改进,谢 ...
用while一旦条件满足就是一个死循环,里面没有修改条件的语句
页:
[1]