Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The 'b' Word
#1
Another Project I Am Working On Here The Problem Is:
How To Remove That 'b' Word In Binary
Output:
Please Type The Number: 0x3 The 0x3 In Decimal Number Is = 3 The 0x3 In Binary Number Is = 0b11
Here Is The Source Code
#All Bases Start Here
#All Bases End Here
def IsNumericBase(s, base):
 try:
  int(s, base)
  return True
 except ValueError:
  return False
def isDeci(s):
    return IsNumericBase(s, 10)
# Returns True if <s> is binary number string
def IsBinaryString(s):
 return IsNumericBase(s, 2)

# Returns True if <s> is octal number string
def IsOctalString(s):
 return IsNumericBase(s, 8)

# Returns True if <s> is hexadecimal number string
def IsHexadecimalString(s):
 return IsNumericBase(s, 16)

#Main Def Starting
def maincheck(temp):
    a = isDeci(temp)
    if a == False:
        b = IsBinaryString(temp)
        if b == False:
            oc = IsOctalString(temp)
            if oc == False:
                hexa = IsHexadecimalString(temp)
                if hexa == False:
                    print("Only Hex,Numbers,Binary And Octal Are Supported")
                else:
                    print("The " + str(temp) +" In Decimal Number Is = ",int(temp, 16))
                    print("The " + str(temp) +" In Binary Number Is = ",bin(int(temp,16)))
            else:
                print("Is " + str(temp) +" Octal Number? = ",hexa)
        else:
            print("Is " + str(temp) +" Binary Number? = ",b)
    else:
        print("Is " + str(temp) +" Decimal Number? = ",a)
#Main Def Ending 

if __name__ == "__main__":
    print("\t\tWelcome To Hex_To_Decimal_Binary_Octal\n")
    #for i in range(1,6):
    temp = input("Please Type The Number: ")
    maincheck(temp)
Reply


Messages In This Thread
The 'b' Word - by Harshil - Aug-11-2020, 04:29 PM
RE: The 'b' Word - by deanhystad - Aug-11-2020, 05:12 PM
RE: The 'b' Word - by buran - Aug-11-2020, 05:34 PM
RE: The 'b' Word - by Harshil - Aug-12-2020, 08:39 AM
RE: The 'b' Word - by buran - Aug-12-2020, 08:41 AM
RE: The 'b' Word - by Harshil - Aug-12-2020, 03:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,455 Aug-12-2021, 04:25 PM
Last Post: palladium
  Python Speech recognition, word by word AceScottie 6 15,867 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  print a word after specific word search evilcode1 8 4,727 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  difference between word: and word[:] in for loop zowhair 2 3,628 Mar-03-2018, 07:24 AM
Last Post: zowhair

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020