我编写了一个程序来检查我在纸上解决方案的正确性(它是正确的)。
任务:求从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这样的语言中,可以更优雅地编写相同的代码。
注:是的,这是一个作业,但不是我的 - 我只是帮了一个人 ;-)