Question: Python: Write a function getInt(question) that asks the user for a number. If the input is not an int, ask again. If the user enters

Python:

Write a function getInt(question) that asks the user for a number. If the input is not an int, ask again. If the user enters exit, the program will call sys.exit() to exit immediately. Use the question given as the output to the user.

Write a function binaryStr(num,bits) that converts the the number num to a binary string with bits bits. If the number is to big to fit in the bits given, truncate it. Make a string using the "1" and "0" characters.

Python: Write a function getInt(question) that asks the user for a number.If the input is not an int, ask again. If the userenters exit, the program will call sys.exit() to exit immediately. Use the

As we saw in lecture, each number is represented by a binary value. The number of bits in the binary number determines the maximum value that can be stored For example, an 8 bit number can store from 0 to 255 We can convert a number to Binary through repeated division Take 254 as an example 254 % 2-0 254//2 127 127 % 2-1 127 //2-63 63 % 2-1 63//2-31 31 %2-1 31 //2 15 15%2-1 15//2 7 7%2-1 7//2 3 3%2-1 3//2-1 1%2:1 1//2 0 When the quotient is equal to 0, we have no more values. The binary value is the remainders read from bottom to top

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!