sel=int("Determine input number (16/10/8/2) :")
if sel != 16 or 10 or 8 or 2:
print ("Error")
if sel == 16 or 10 or 8 or 2:
num=input ("Enter Value:")
if sel == 16 :
num10 = int(num,16)
if sel == 10 :
num10 = int(num,10)
if sel == 8 :
num10 = int(num,8)
if sel == 2 :
num10 = int(num,2)
print ("hex==>", hex(num10))
print("decimal==>", num10)
print("Hex ==>", oct(num10))
print("Binary ==>",bin(num10))
I made a program like this and made it say 16, 8, 2, 10 or something else, but even if I type 16, it says it's an error. How do I get a program to print out an error when I put a number other than the specified number?
python base-conversion
That's not how you use the or command. Make the following corrections.
if sel != 16 and sel != 10 and sel != 8 and sel != 2:
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Understanding How to Configure Google API Key
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.