当前位置:首页 > python

高质量练习题

admin5个月前 (01-25)python6396
# 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

分享给朋友:

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

DrissionPage执行js

from DrissionPage import ChromiumPage url = 'https://www.bilibili.com/video/BV1jfztYyEn3/' page = Chr…

dp爬携程

# https://hotels.ctrip.com/hotels/list?starlist=5&highPrice=-1&barCurr=CNY&sort=1 from DrissionPage import ChromiumPa…

一道数学题

# 已知50个1998相乘的结果是a,a的各位数的和是b, b的各位数的和是c,c的各位数的和是d, # 求d的值 a = 1998 ** 50 print(a) str_a = str(a) b&nbs…

制作自动答题脚本教程

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

《Python入门100题》之第一题:三位组合

第一题:有1,2,3,4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?list1 = [1, 2, 3, 4] list2 = [] for a in list1:  &…

《Python入门100题》之第二题:范围数字查找

编写一个程序:查找所有此类数字,它们可以被7整除,但不能是5的倍数在(2000和3200之间)均包含在内list1 = [] for i in range(2000, 3201):     if&…