+ 2

Why does my code have error ??

Hi can you tell me why is my this code isn't working?? # Input 0 for binary to int or 1 for int to binary # Then input your number a = int(input ()) if a == 0: b = bin (input ()) b = str (int (b)) print (b[2:-1], b[-1]) elif a == 1: c = int (input ()) c = str (bin (b)) print (c[2:-1], c[-1]) https://code.sololearn.com/cRDPMj5naXcy/?ref=app

20th Aug 2020, 5:49 AM
Harsh Rahevar
Harsh Rahevar - avatar
2 Réponses
+ 4
the code can be done a bit shorter, also there are some issues: a = int (input ()) if a == 0: print(int(input(),2)) elif a == 1: print(bin(int(input()))[2:])
20th Aug 2020, 10:39 AM
Lothar
Lothar - avatar
0
In 6 line use bin(int(input()))
20th Aug 2020, 6:11 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar