【发布时间】:2022-01-06 09:28:29
【问题描述】:
我有一个两位数(例如 29))并希望进一步减少到一位数。我怎么能在python中做到这一点?我应该在 while 循环中使用该函数吗? 例如
29 -> 11 -> 2
结果: [29,11,2]
x=input('Input digit: ')
result=0
box=[]
def add_two(x):
bz=[]
for i in str(x):
bz.append(int(i))
s=sum(bz)
return s
box=[]
a=0
while len(str(x))>1:
【问题讨论】:
-
你可以简化你的问题以删除无用的东西(生日的东西),只保留最低限度;)
-
我把问题简化了
标签: python function while-loop