python中没有响应

muzaaf nameer firdausi

我写了一个简单的代码:输入任何数字和一个数字并计算数字在数字中的次数。

我写的代码是:

num= int(input("enter a number"))
n=num
digit = int(input("enter the digit"))
times=0
while n > 0 :
    d = n%10
    if d==digit :
        times += 1
        continue
    else:
        continue
    n=n//10
print ("no. of times digit gets repeated is ", times)

当我尝试这段代码时,不知何故它什么也没给我

大赏金

删除elseandcontinue语句,因为循环总是遇到continue并且永远不会去n=n//10

num= int(input("enter a number"))
n=num
digit = int(input("enter the digit"))
times=0
while n > 0 :
    d = n%10
    if d==digit :
        times += 1
    n=n//10
print ("no. of times digit gets repeated is ", times)

输出:

enter a number1111222233344567433232222222
enter the digit2
no. of times digit gets repeated is  12

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章