【发布时间】:2023-02-21 22:20:59
【问题描述】:
我正在用 python 3 编写代码来显示给定数字的位数。代码如下:
count=0.
def fun(n):
global count_e
if n<0 :
count_e+=1
else:
res=fun(N/10)
count_e+=1
N=int(input())
fun(N)
print (count_e)
我收到缩进错误。我不知道如何进行。
我试图用我的 python 代码解释问题。我期待有建议的回复。
【问题讨论】:
-
错误说问题出在哪里?
-
取消缩进你的如果堵塞。你还需要定义count_e.然后你需要考虑负数以及 float 和 int 之间的差异 - 例如,如果n == 12.5?您是否在这里考虑过递归的含义?
标签: python