Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with this question 1. Write a Python program which will accept a non-negative decimal integer from the user and produce the binary
I need help with this question
1. Write a Python program which will accept a non-negative decimal integer from the user and produce the binary equivalent using the algorithm from section 4.2.1, page 156 of our textbook. Program requirements: 1.1. Do not use recursion, Python lists, the list() function, the reversed() function, bin(), string indexing, the Python for loop, or the .split() method. Do not define a function to do the decimal-to-binary conversion. 1.2. Do demonstrate that you can implement a step-by-step algorithm to accomplish the conversion, 1.3. Do not treat the user's input as a series or list or sequence of characters. 1.4. Include both header comments and explanatory comments in the code. Include an explanatory comment in the code for each loop and for each "if", "elif" and "else". 1.6. Display a short explanation of what the program does. 1.7. Prompt for, and reads, an integer from the user. Immediately convert the user input into a decimal integer using the int() function. 1.8. Reject any number less than zero. 1.9. Create a variable containing an empty character string. 1.10. Create a copy of the user's integer in an integer variable named "working". (This is so that we still have the original value available if we need it, for example in step 1.12 below.) 1.11. Use a loop and one or more conditional statements (if/eliflelse) to process the integer using successive division by 2, as described in section 4.2.1, page 156 or our textbook. The loop will most likely do the following operations: 1.11.1. If the working number is odd, prepend the character string "1" to your string variable, otherwise prepend the character string "0" to your string variable. 1.11.2. Print the working number and the character string. 1.11.3. Divide the working number by 2, throwing away the remainder. (This throws away the bit you just tested.) 1.11.4. If the working number is zero, break out of the loop. If the working number is not zero, run through the loop again. 1.12. After the working number has been processed, report the user's original number and its binary representation as stored in the character string you have built your program with several positive values, then test it with zero. Fix as needed. Turn in your program to this week's assignment folder. 3 Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started