我是python新手,我正在尝试从循环计算数字。让这个问题让你容易理解。你知道吗
我用python编写了这个程序:
print("Please enter your case:")
myCase = input("\nEnter: ")
for numCase in range(0, int(myCase)):
print("\nPlease enter your number: ")
myNum = input("\nEnter: ")
for i in myNum:
divideNum = int(myNum) % int(i)
print(divideNum)
现在在运行这个程序之后,它会给出以下输出:
Please enter your case:
Enter: 2
Please enter your number:
Enter: 456856
0
1
4
0
1
4
Please enter your number:
Enter: 12
0
0
//You could see here, these are the result of the remainder.
问题
我想计算零在案例1和案例2中出现two
次。你可以在我的程序中看到我在计算给定输入的Remainder
。你知道吗
下面是另一个要理解的例子!你知道吗
假设,我给出输入:
Enter: 25621
1
1
1
1
0
现在,我想计算零出现在one time
。那么,如何在python中实现这个过程呢?你知道吗
请帮忙!你知道吗
要计算计算值中的零数,有许多选项。你知道吗
这里有两个:
使用变量存储计数:
或者使用list comprehension从值创建一个零列表,然后使用^{} 函数,该函数将循环嵌入列表结构中:
相关问题 更多 >
编程相关推荐