当前位置:首页 > python

高质量练习题

admin9个月前 (01-25)python6550
# 1.请问在 1 至 202504(含)中,有多少个数的各个数位之和是 5 的整数倍。
# 例如:5,19,8025 都是这样的数。
# 方法1
count = 0
for i in range(1, 202505):
    ret = 0
    for x in str(i):
        ret += int(x)
    if ret % 5 == 0:
        count += 1
print(count)
# 方法2
# count = 0
# for i in range(1, 202505):
#     get_sum = 0
#     temp = i
#     while temp > 0:
#         # 取最后一位,求和
#         get_sum += temp % 10
#         # 去掉最后一位
#         temp = temp // 10
#     if get_sum % 5 == 0:
#         count += 1
# print(count)


扫描二维码推送至手机访问。

版权声明:本文由匡民博客发布,如需转载请注明出处。

本文链接:https://kuangmin.top/post/99.html

分享给朋友:

“高质量练习题” 的相关文章

dp查找iframe元素

from DrissionPage import ChromiumPage dp = ChromiumPage() # # 同域的直接拿 dp.get('https://www.qiju.cc/vod/play/…

制作自动答题脚本教程

基本的操作,联系下不错Python DrissionPage 制作自动答题脚本_哔哩哔哩_bilibili…

ddddocr的安装使用

pip install -i https://mirrors.bfsu.edu.cn/pypi/web/simple/  ddddocrfrom DrissionPage import ChromiumPage imp…

跳转新标签页获取元素

from DrissionPage import Chromium browser = Chromium() tab = browser.latest_tab tab.get('https://www.163.c…

列表添加数据的方法

# 列表添加数据的方法 # 末尾追加:list.append(obj) a = [1, 2, 3, 4, 5] a.append(6) print(a) # 指定位置插入:list.insert(in…

python读文件操作

# 打开名为 '111.txt' 的文件,以只读模式读取,文件编码为 utf-8 with open('111.txt', 'r', encoding='utf-8'…