Results 1 to 2 of 2
  1. Cash5 I suck at coding need some help


    Okay, so I have to make a code in python that converts from decimal to binary decimal to hexadecimal and lastly from binary to decimal. This is what I have so far:

    Decimal to binary

    Spoiler


    decimal to hexadecimal
    Spoiler


    Binary to decimal
    Spoiler



    I try to run these and I keep getting syntax errors so the program won't run and I have no idea how to fix them. So could anyone help me correct them not necessarily do them for me but at least give me a better explanation of where the errors are and what to do to fix them any help at all would be appreciated I'm at my wits end here.

  2. Default Re: I suck at coding need some help


    Good news is decimal to binary and binary to decimal seem to work fine. The only one that seems to have a problem is decimal to hexadecimal.

    Code:
    def decToHex():
        #Get number from user
        number=int(input("enter a postive number ")#Missing a parenthesis 
        if(number is<= 0) #What's that is doing there? Also, need a colon
            0)#What's this?
            print("enter a postive number")
            if(number=0) #Should not be an assignment, also a colon
                print("the hexadecimal value of 0 equals 0")
        else #Colon needed here
            hstr=" "
            q=number
            while(q>0):
                if(q%16<10):
                    hstr=str(q%16)+hstr
                elif(q%16==10):
                    hstr="A"+hstr
                elif(q%16==11):
                    hstr="B"+hstr
                elif(q%16==12):
                    hstr="C"+hstr
                elif(q%16==13):
                    hstr="D"+hstr
                elif(q%16==14):
                    hstr="E"+hstr
                elif(q%16==15):
                else: #This else probably shouldn't be here
                    hstr="F"+hstr
                q=q//16
        print(number, "converted to hexadecimal is " , hstr)
    If you make the changes where I added comments it should compile.

    I would also highly recommending downloading a good python IDE - I currently use PyCharm and it works pretty well.

  3.  

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •