Decipher Binary Number
Taak
Swipe to start coding
So far, so good 😃 Convert binary code to the decimal one. Fill the gaps and follow the algorithm. The result of your manipulations is a specific number in math .
- Create variable
decimal_number
for storing converted decimal number and assign0
to it. - Print the binary number.
- Define the variable
power
and assign0
to it. - Define the loop that executes till the
binary number
is0
. - Count the remainder of division
binary_number
by10
and assign it to the variablelast_digit
. - Multiply
last_digit
by the2
raised to the relevant power. - Add the
result
to thedecimal_number
. - Decrease
binary_number
using integer division by10
. - Increase
power
by1
. - Print the
decimal number
.
Oplossing
99
1
2
3
4
5
6
7
8
9
10
11
12
binary_number = 101110010
decimal_number = 0
print("The number in binary numeral system is:", binary_number)
power = 0
while binary_number != 0:
last_digit = binary_number % 10
result = last_digit * pow(2, power)
decimal_number = decimal_number + result
binary_number = binary_number // 10
power = power + 1
# Printing the result
print("The number in decimal numeral system is:", decimal_number)
Note
You received one of the Armstrong number: the sum of the cubes of its own digits, let me explain this: 370 = 3^3 + 7^3 + 0^3 = 27 + 343 + 0 = 370
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 3
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
binary_number = 101110010
# Create variable decimal_number for storing converted decimal number and assign 0 to it
___ = ___
# Output the binary number
print("The number in binary numeral system is: ", ___)
# Define the variable power and assign 0 to it
___ = ___
# Define the loop that executes till the number is zero
___ binary_number != ___:
# Count the remainder of division binary_number by 10 and assign it to the variable last_digit
___ = binary_number ___
# Multiply digit by the 2 raised to the relevant power
result = last_digit * pow(____, ____)
# Add the result to the decimal_number
decimal_number = decimal_number ___ result
# Decrease binary_number using integer division by 10
binary_number = binary_number ___ 10
# Increase power by 1
power = power ___ 1
# Output the decimal number
print("The number in decimal numeral system is: ", ______)
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.