{ "question_id": 7436880, "question_title": "计算出因子里面4和7的个数", "question_content": "
输入一个正数n,计算出因子里面分别有几个4和7,输出因子中4和7的个位数
", "difficulty": "简单", "answer_id": 53409217, "answer_content": "\nn = int(input("输入数字:"))\nfactor = [n] # 包括n?\nnum = 1\nwhile num <= n/2+1:\n if n % num == 0:\n factor.append(num)\n num = num + 1\nprint(factor)\nm = [str(i) for i in factor]\ncount4 = 0\ncount7 = 0\nfor i in m:\n if '4' in i:\n count4 += 1\n print('以4结尾的因子的个位数:', int(i)%10)\n if '7' in i:\n count7 += 1\n print('以7结尾的因子的个位数:', int(i)%10)\nprint('因子里面分别有{0}个4和{1}个7'.format(count4,count7))
\n\n这里的因子包括了数字本身,如果不想包括可以将factor 初始化为[]
\n\n输入:140
\n\n输出:
\n\n\n[140, 1, 2, 4, 5, 7, 10, 14, 20, 28, 35, 70]\n以4结尾的因子的个位数: 0\n以4结尾的因子的个位数: 4\n以7结尾的因子的个位数: 7\n以4结尾的因子的个位数: 4\n以7结尾的因子的个位数: 0\n因子里面分别有3个4和2个7\n\n
\n", "tag_name": "python", "python": "n = int(input(\"输入数字:\"))\nfactor = [n] \nnum = 1\nwhile num <= n/2+1:\n\tif n % num == 0:\n\t\tfactor.append(num)\n\tnum = num + 1\nprint(factor)\nm = [str(i) for i in factor]\ncount4 = 0\ncount7 = 0\nfor i in m:\n\tif '4' in i:\n\t\tcount4 += 1\n\t\tprint('以4结尾的因子的个位数:', int(i)%10)\n\tif '7' in i:\n\t\tcount7 += 1\n\t\tprint('以7结尾的因子的个位数:', int(i)%10)\nprint('因子里面分别有{0}个4和{1}个7'.format(count4,count7))", "topic_link": "https://bbs.csdn.net/topics/600470505", "status": 1, "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", "license": "csdn.net", "notebook": { "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/36.ipynb?type=file" }, "notebook_enable": 1 }