Question: Under the hood, all Python data types need to be represented as binary integers to be understood by the computer's hardware. You will write a

Under the hood, all Python data types need to be represented as binary integers to be
understood by the computer's hardware. You will write a program to peek under the hood at
the decimal and binary representation of characters. You will need two new Python functions
to perform the conversion that work similar to the built in type conversion functions. The ord()
function is used to convert a letter to an integer. The bin() function converts an integer to a
string representation of a binary number. To see how these functions work you should play
with these functions in the shell, as we do in this example:
num =ord('A')
print (num)
65
> binary = bin (65)
print(binary)
0b1000001
Write a program that asks the user for a letter and prints out both the integer and binary
representations of the letter. It should ask the user for a character and then output the integer
and binary representations of the character. Here is an example of what the output should
look like if the user types the letter 'A' at the prompt:
Enter a character:A
A corresponds to the integer 65 which is 0 b 1000001 in binary.
Note in the output where we have inserted the character A and the decimal and binary
representations of that character. You will need to write a print statement that includes all
three as well as the intervening text.
 Under the hood, all Python data types need to be represented

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!