读入一个整数n和一个数字d,统计并输出整数n中数字d的个数。要求定义并调用函数countdigit (number, digit),它的功能是统计整数number中数字digit的个数。例如, cou
时间: 2023-05-03 15:02:24 浏览: 110
这道题目是要求我们输入一个整数n和一个数字d,统计并输出整数n中数字d出现的次数。要求定义并调用函数countdigit (number, digit),它的功能是统计整数number中数字digit的个数。例如,countdigit (112233, 3)的结果是2,因为数字3在112233中出现了2次。
相关问题
读入一个整数,统计并输出该数中2的个数。要求定义并调用函数countdigit(number,digit),它的功能是统计整数number中数字digit的个数。
可以这样实现:
def countdigit(number, digit):
count =
while number > :
if number % 10 == digit:
count += 1
number //= 10
return count
num = int(input("请输入一个整数:"))
count = countdigit(num, 2)
print("数字2在整数{}中出现了{}次。".format(num, count))
读入一个整数,统计并输出该数中指定数字的个数,要求调用函数countdigit(number,digit),他的功能是统计整数number中数字digit的个数。;例如,countdigit(1009
这道题的要求是编写一个函数 countdigit(number, digit),功能是统计整数 number 中数字为 digit 的个数。例如,countdigit(1009, 0) 的结果应该为 1,因为数字 0 在整数 1009 中出现了 1 次。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)