Computers and Technology

This is my code and i cant find what the problem is could you help me #!/usr/bin/env python
# coding: utf-8

# In[2]:

while True: # Program will keep running until we quit it ourselves , Infinite loop
print("\n\n BINARY / DECIMAL CONVERSION \n\n") # Title
choice = input("1- Binary to Decimal conversion \n2- Decimal to Binary Conversion \n3- Quit \n\n =>") #Menu

if choice == "1": # binary to decimal
binary = (list(input("\n\nInput a binary number: "))) #input binary number and covert it into list
decimal = 0 #this variable will hold final decimal converted value
i = 0
binary = (list(input("\n\nInput a binary number: ")))
digit = binary. pop() # pop is a method of list which removes and return last item of list
for i in range(len(binary)): #Loop number of digits of binary number time

if digit == '1': #if digit is one , add 2 raised to the power i to the decimal variable

decimal = decimal + pow(2, i)
print("The decimal value of the number is: ", decimal) #print result

if choice =="2":#decimal to binary

decimal = int(input("\n\nInput a Decimal Number: ")) #input decimal number and convert it into integer
i = 0
binary = [] # this list will hold final binary result
while decimal!=0: # while decimal value is not equal to zero
rem = decimal%2 #remainder of decimal divided by 2
binary. insert(i, rem) #insert remainder on ith index of binary list
i = i+1
decimal = int(decimal/2) #dividing list by 2

i = i-1
print("\nThe Binary value of the number is:")
binary. reverse() # We need to reverse the list to get the result we want

for i in range(len(binary)):
print (binary[i],end ="") #printing each index of binary list one by one

if choice == "3":#Quit
print("\n\n Program Terminated Successfully ")
exit() #Terminates the program

# In[ ]:

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 07:30, akluke6059
Events and conditions that happen within an organization that are somewhat easier to deal with when responding to change are called
Answers: 1
image
Computers and Technology, 22.06.2019 14:30, binodkharal2048
Hi plz 11 ! when planning a table, what step comes first: "define the column headers" or "calculate the number of columns/rows"? a. calculate the number of columns/rows b. define the column headers
Answers: 1
image
Computers and Technology, 24.06.2019 15:40, elgallo5399
In the above figure, what type of cylinder arrangement is shown in the figure above? a. l-type b. v-type c. in-line d. horizontal pls make sure its right if its rong im grounded for 3months
Answers: 1
image
Computers and Technology, 25.06.2019 12:00, dariannalopez5902
The user needs to add a thick dark green border around a chart in powerpoint. the user can do this in chart tools by choosing?
Answers: 1
Do you know the correct answer?
This is my code and i cant find what the problem is could you help me #!/usr/bin/env python
...

Questions in other subjects:

Konu
Mathematics, 16.09.2020 01:01
Konu
Mathematics, 16.09.2020 01:01
Konu
English, 16.09.2020 01:01
Konu
Mathematics, 16.09.2020 01:01
Konu
Mathematics, 16.09.2020 01:01
Konu
Mathematics, 16.09.2020 01:01
Konu
Mathematics, 16.09.2020 01:01
Konu
Mathematics, 16.09.2020 01:01
Konu
Mathematics, 16.09.2020 01:01
Konu
Mathematics, 16.09.2020 01:01