简体   繁体   English

乘法持久性程序不起作用

[英]Multiplicative persistence program not working

This program is supposed to find the multiplicative persistence of an input number but I can't get it to work.该程序应该找到输入数字的乘法持久性,但我无法让它工作。 It simply closes the window when open it.它只是在打开 window 时关闭它。 I can't think of anything that's wrong here.我想不出这里有什么问题。

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 

Nvm I got it working 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)

The operator for integer division is apparently // and not /. integer 除法的运算符显然是 // 而不是 /。 Welp C++ habits die hard. Welp C++ 习惯难改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM