File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -44,23 +44,23 @@ def binary_count_trailing_zeros(a: int) -> int:
44
44
doctest .testmod ()
45
45
46
46
47
- #counting number of 0s and 1s in a binary number
47
+ # counting number of 0s and 1s in a binary number
48
48
def count_zeros_and_ones (binary_number ):
49
49
# Convert the binary number to a string if it's not already
50
50
binary_str = str (binary_number )
51
-
52
- count_zeros = binary_str .count ('0' )
53
- count_ones = binary_str .count ('1' )
54
-
51
+
52
+ count_zeros = binary_str .count ("0" )
53
+ count_ones = binary_str .count ("1" )
54
+
55
55
return count_zeros , count_ones
56
56
57
+
57
58
# Get user input
58
59
binary_number = input ("Enter a binary number: " )
59
60
60
61
# Validate input
61
- if all (bit in '01' for bit in binary_number ):
62
+ if all (bit in "01" for bit in binary_number ):
62
63
zeros , ones = count_zeros_and_ones (binary_number )
63
64
print (f"Number of 0s: { zeros } , Number of 1s: { ones } " )
64
65
else :
65
66
print ("Invalid input! Please enter a valid binary number." )
66
-
You can’t perform that action at this time.
0 commit comments