首页 > 解决方案 > 乘法持久性程序不起作用

问题描述

该程序应该找到输入数字的乘法持久性,但我无法让它工作。它只是在打开窗口时关闭窗口。我想不出这里有什么问题。

import time
a = int(input("Enter the number"))
s = 1
n = 0
while (a>0):
    while (a>0):
        b = a%10
        s = s*b
        a = a/10
    n = n+1
    a = s
    print(s)
time.sleep(10)
input = 277777788888899 
expected output = 277777788888899 4996238671872 438939648 4478976 338688 27648 2688 768 336 54 20 0 
current output = 0 

标签: pythonpython-3.x

解决方案


Nvm 我让它工作了

import time

a = 277777788888899
s = 1
n = 0
print(a)
while (a>0):
    while (a>0):
        b = a%10
        s = s*b
        a = a//10
    n = n+1
    a = s
    print(s)
    s = 1 
n = str(n)
print('the multiplicative persistence is '+n)

time.sleep(10)

整数除法的运算符显然是 // 而不是 /。Welp C++ 习惯很难改掉。


推荐阅读