直接根据描述来解题

while True:
    try:
        num = int(input())
    except:
        break
    
    count = 0
    for i in range(num, 6, -1):
        if i % 7 == 0:				# 7的倍数
            count += 1
        else:						# 某一位上出现了7
            tmp = i
            while tmp:
                if tmp % 10 == 7:
                    count += 1
                    break
                tmp //= 10
    print(count)