我正在处理this series of problems。在
我不明白问题11和使用int()
的方式。我知道将x
直接转换为int
会导致一些零的丢失,所以这样做是不可能的,但我不明白是什么
intp = int(p,2)
是应该做的。打印出intp
我得到以下值,4,3,10,9
。这与0100,0011,1010,1001
有什么关系?为什么一开始就丢失了零?在
问题11
2级
^{pr2}$Question: Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are to be printed in a comma separated sequence.
Example:
0100,0011,1010,1001
Then the output should be:
1010
Notes: Assume the data is input by console.
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
要将二进制数转换为十进制数,我们必须使用python内置的int函数,该函数以二进制数和数字系统的基为参数。 示例:
正如上面的grumpy注释所建议的,int函数接受第二个参数,这是转换的基础。所以它取绑定到p的base2(二进制)变量,并将其转换为以10为基数的整数,也就是说,普通人。在
相关问题 更多 >
编程相关推荐