Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3) binary.py Recall that we briefly discussed the binary system (or base two) in class. A number is represented in binary by a sequence of

image text in transcribed
image text in transcribed
3) binary.py Recall that we briefly discussed the binary system (or base two) in class. A number is represented in binary by a sequence of 1's and O's (also known as bits), which have place values given by powers of 2 instead of powers of 10 In an ten-digit binary number, the left digit would be the 512's digit, the next digit would be the 256's digit, the third would be the 128's digit, followed by the 64's, 32's, 16's, 8's, 4's, 2's, and I's digits. For example, 0001011101 in binary would represent the (base-10) number 93, because this number has, reading from the left, no 512, no 256, no 128, one 64, no 32, one 16, one 8, one 4, no 2, and one 1, and 64 + 16 +8+4+ 1 = 93. And 00000111 would represent the (base-10) number 7, since this number has no 512, no 256, no 128, no 64, no 32, no 16, no 8, one 4, one 2, and one 1. Write a program that takes no input from the user, but prints a random 10-digit binary number, and its base-10 equivalent. Specifically, your program should use the random module to pick 10 random numbers that should each be either 0 or 1. The program should then display those 10 digits in a row, together with the equivalent decimal number: When you run your program, a sample run might look like this: Here's a randon example of binary! The binary number 0 0 10001 1 1 0 in the same as the decimal number 142. or this Here's a random example of binary The binary number 0000 1100111 the same as the decinal number 31 Every time I run the program, I should be a different number (between 0 and 1023). You should be able to complete this program only using things we have discussed already in the clou don't use or tuples (there are sequences of variables enclosed in either or (), don't we loops, and definitely don't Every time I run the program, I should get a different number (between 0 and 1023). You should be able to complete this program only using things we have discussed already in the class: don't use lists or tuples (these are sequences of variables enclosed in either [] or O), don't use loops, and definitely don't use any of Python's functions for binary (like bin). If/else statements are acceptable, but unnecessary. Instead, use mathematics - multiplication, exponentiation. Specifications: your program must accept NO user input. use random to generate ten different random numbers - each should be 0 or 1. display the eight generated digits, as well as the equivalent decimal number, in the manner shown above. In particular, I want to see binary numbers listed like 0 0 1 0 1 0 1 1 0 0, not like (0, 0, 1, 0, 1, 0, 1, 1, 0, 0) (0010101100, without the spaces in between, is acceptable.) display different numbers each time the program is run. only use techniques that we have discussed in class thus far - in particular, no use of the bin function, no use of loops, and no use of lists or tuples

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago