subject

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[ ]:

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:10
Ihave a music player on my phone. i can buy songs, add them to playlists and play them. obviously it would be redundant to store each song in each playlist; each playlist is just a list of pointers to the songs. for this lab you will simulate this behavior. your program will need to have options to: add songs to the system library (you will store the text of the first line of the song, rather than the audio) add playlists add songs to a playlist list playlists play a playlist list all of the songs in the library with a count of how many times each song has been played remove a song from a playlist remove a playlist remove a song from the library (and thus from all playlists that contain it) note that we will not be checking many error cases. in real programming this would be bad, you should usually try to recognize and respond to as many types of errors as you can. in the context of class we are trying to acquaint you with as many concepts as possible, so for the sake of educational efficiency we will not be checking most errors in this lab, you may assume that your user provides correct input. you may add all appropriate error testing if you wish, but we will not be testing for it.
Answers: 2
question
Computers and Technology, 22.06.2019 15:10
Which activity should be part of a long-term plan to positively affect yourhealth? oa. wearing regular clothing when handling toxinsob. not worrying about secondhand smokeoc. avoiding excessive exposure to sunlightod. drinking only well water
Answers: 1
question
Computers and Technology, 23.06.2019 01:30
Negative methods of behavior correction include all but this: sarcasm verbal abuse setting an example for proper behavior humiliation
Answers: 1
question
Computers and Technology, 23.06.2019 02:30
Experimental data that is expressed using numbers is said to be
Answers: 1
You know the right answer?
This is my code and i cant find what the problem is could you help me #!/usr/bin/env python
...
Questions
question
Mathematics, 21.05.2021 22:40
question
Mathematics, 21.05.2021 22:40
question
Mathematics, 21.05.2021 22:40
Questions on the website: 13722361