Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON Write a program that will take a 2 decimal numbers, convert them to binar

ID: 3765167 • Letter: P

Question

PYTHON

Write a program that will take a 2 decimal numbers, convert them to binary and add the using the adder Circuit. Create the decimal-binary conversion table in excel, save it as a CSV file and read it into a two dimensional array (as strings). You will have to convert the strings into their numeric counterparts. When running the program, the user should be able to enter two decimal numbers from 1 to 10, display the binary counterparts do the math using the adder circuit and display the binary and decimal answers

Explanation / Answer

CSV file (decbin.csv) for decimal(1-10) to binary conversion:

--------------------------------

1,0001
2,0010
3,0011
4,0100
5,0101
6,0110
7,0111
8,1000
9,1001
10,1010

------------------------------------------------

Basic program to read a csv file, read two numbers from keyboard, and display the binary counterpart of read numbers:

---------------------------------------

#imports csv package
import csv
#reading csv file
print "Reading CSV file..."
dec_bin_table = list(csv.reader(open('decbin.csv')))

#rows and columns in dec_bin_table
rows=len(dec_bin_table)
cols=len(dec_bin_table[0])
#print rows
#print cols

#two numbers to add
print "Reading two deimal integers..."
num1 = input("Enter first number:")
num2 = input("Enter second number:")

#binary equivalents of num1 and num2
for i in range(rows):
    if num1 == int(dec_bin_table[i][0]):
        num1_bin=dec_bin_table[i][1]
        break
for i in range(rows):
    if num2 == int(dec_bin_table[i][0]):
        num2_bin=dec_bin_table[i][1]
        break

#show the binary counterparts of num1 and num2
print "Number 1:"+str(num1)+", Binary number:"+num1_bin
print "Number 2:"+str(num2)+", Binary number:"+num2_bin

'''
Code to use adder circuit to add
two binary numbers goes here.
'''

------------------------------------------------

Note: You have not mentioned the adder circuit to use.