【发布时间】:2011-05-01 00:58:32
【问题描述】:
我编写了一个程序来检查我对纸上解决方案的想法是否正确(确实如此)。
任务:从 10 到 200 的所有数字相乘后有多少个零。
48,手动计算很简单。
我从来没有认真写过python,这就是我得到的:
mul = 1
for i in range(10, 200 + 1):
mul *= i
string = str(mul)
string = string[::-1]
count = 0;
for c in str(string):
if c == '0':
count += 1
else:
break
print count
print mul
我敢打赌,用类似 python 的语言编写同样更优雅的代码是可能的。
ps:是的,这是作业,但不是我的 - 我只是帮助了一个人;-)
【问题讨论】:
标签: python