0
0
Intro to Computingfundamentals~10 mins

Binary number system in Intro to Computing - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert the decimal number 5 to binary using the built-in function.

Intro to Computing
binary_value = bin([1])
Drag options to blanks, or click blank then click option'
A8
B10
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a binary number instead of a decimal number inside bin()
Confusing the base of the number
2fill in blank
medium

Complete the code to convert the binary string '1010' to a decimal number.

Intro to Computing
decimal_value = int('[1]', 2)
Drag options to blanks, or click blank then click option'
A1010
B10
C2
D1001
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a decimal number instead of a string
Forgetting to specify base 2
3fill in blank
hard

Fix the error in the code to correctly convert the decimal number 12 to binary without the '0b' prefix.

Intro to Computing
binary_str = bin(12)[1]
Drag options to blanks, or click blank then click option'
A[1:]
B[2:]
C.substring(2)
D.slice(2)
Attempts:
3 left
💡 Hint
Common Mistakes
Using JavaScript string methods like .slice() or .substring() in Python
Using incorrect slicing syntax
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps decimal numbers 1 to 5 to their binary strings without the '0b' prefix.

Intro to Computing
binary_dict = {num: bin(num)[1] for num in range(1, 6) if num [2] 3}
Drag options to blanks, or click blank then click option'
A[2:]
B>
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect slicing syntax
Using wrong comparison operators
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase hexadecimal digits to their decimal values, including only digits greater than 9.

Intro to Computing
hex_dict = { [1]: int([2], 16) for [3] in ['A', 'B', 'C', 'D', 'E', 'F'] if int([3], 16) > 9 }
Drag options to blanks, or click blank then click option'
Adigit
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently
Forgetting to specify base 16 in int()