python - 乘法持久性程序不起作用
问题描述
该程序应该找到输入数字的乘法持久性,但我无法让它工作。它只是在打开窗口时关闭窗口。我想不出这里有什么问题。
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 我让它工作了
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++ 习惯很难改掉。
推荐阅读
- python - Keras - 使用大量功能
- mongodb - 执行聚合时出现mongodb错误
- c++ - 为什么我不能直接用 strcpy 复制 C 字符串的某个字符,而必须使用辅助字符串?
- vue.js - 在没有 vuex-persist 的情况下保留 Vuex 状态数据
- gtk - 非编译语言的构建系统
- mysql - MySQL在尝试创建过程时抛出错误“语句不完整,如果”
- ios - 如何快速创建具有特定类型别名的闭包?
- mysql - 无法调用存储过程 错误代码 1305
- unity3d - “找不到 DllAttribute”:从统一调用 .jslib 文件中的函数
- python - 用户在 numpy 中为 argsort() 定义的决胜局