Другие ответы указывают на ваше неправильное использование continue
, но есть пара Pythoni c способов сделать это.
divmod()
аккуратно выполняет деление и модуль в одна операция:
num = int(input("enter a number"))
digit = int(input("enter the digit"))
times = 0
while num > 0:
num, d = divmod(num, 10)
if d == digit:
times += 1
print("no. of times digit gets repeated is ", times)
Вы также можете просто не делать ничего с числами, а со строками, а использовать str.count
:
num = input("enter a number")
digit = input("enter the digit")
print("no. of times digit gets repeated is ", num.count(digit))