201912-1 报数

说来惭愧,作为一个代码能力比较差的小白,我用了比较长的时间才写出了第一题,以此作为记录

遇到的问题

1.在python中,整除符号 / 返回的是浮点数,如果想作为取整来使用,需要用 //
2.注意额外的输出

题目

在这里插入图片描述
代码

下面展示我的比较不好的解题代码

// 比较笨的办法
import os

def if_has(num):
    if (num//10)==0:
        if num==7:
            return True
        return False
    elif num//100==0:
        high=num//10
        low=num%10
        if high!=7 and low!=7:
            return False
        return True
    else:
        high = num //100
        num2= num % 100
        mid = num2 //10
        low = num % 10
        if high!=7 and low!=7 and mid!=7:
            return False
        return True
n=input()
n=int(n)
count=0
a=[0,0,0,0]
curr_num=1
xb=0
test=0
while count<n:
    if curr_num%7==0 or if_has(curr_num):
        curr_num+=1
        a[xb%4]+=1
        xb+=1
        test+=1
    else:
        xb+=1
        curr_num+=1
        count+=1

for  item in a:
    print(item)

网络上看到了其他人的代码,惭愧

//别人的代码
n=int(input())
nonius=-1;
list_times=[0,0,0,0]
count=0;num=0;
while count<n:
    num+=1
    nonius=(nonius+1)%4
    if num%7==0 or '7' in str(num):
        list_times[nonius]+=1
    else:
        count+=1
for i in range(4):
    print(list_times[i])

原文链接:https://blog.csdn.net/ftimes/article/details/104025031
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值