Search scripts - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Search scripts

nawshnawsh Posts: 4Member
Hello I'm fairly new to programming and fairly new to this site. The greatest program I have ever wrote was a phone book program :) . I was sitting here thinking does anyone know if it is possible to write a search program? And what i mean by search is like have an input that says something like I need input and whatever you type in while the program is running it will store it for you . Oh and also before i forget I've been trying for days now to write a program that will convert decimal to binary does anyone know of some source i can look at that will give me some pointers.

Thanks in advance

nawsh

Comments

  • infidelinfidel Posts: 2,900Member
    : Hello I'm fairly new to programming and fairly new to this site. The greatest program I have ever wrote was a phone book program :) . I was sitting here thinking does anyone know if it is possible to write a search program? And what i mean by search is like have an input that says something like I need input and whatever you type in while the program is running it will store it for you .

    You'll have to be a little more specific or clear, I don't understand what you're asking for.

    : Oh and also before i forget I've been trying for days now to write a program that will convert decimal to binary does anyone know of some source i can look at that will give me some pointers.

    What do you have so far?


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

  • nawshnawsh Posts: 4Member
    : : Hello I'm fairly new to programming and fairly new to this site. The greatest program I have ever wrote was a phone book program :) . I was sitting here thinking does anyone know if it is possible to write a search program? And what i mean by search is like have an input that says something like I need input and whatever you type in while the program is running it will store it for you .
    :
    : You'll have to be a little more specific or clear, I don't understand what you're asking for.
    :
    : : Oh and also before i forget I've been trying for days now to write a program that will convert decimal to binary does anyone know of some source i can look at that will give me some pointers.
    :
    : What do you have so far?

    I have :


    #This program converts decimal binary.
    num = 0
    nunum = 0
    a = 0
    b = 0
    c = 0
    d = 0
    e = 0
    f = 0
    g = 0
    h = 0
    i = 128
    j = 64
    k = 32
    l = 16
    m = 8
    n = 4
    o = 2
    p = 1
    num = input("What number would you like to convert?")
    if num > i:
    a = 1
    nunum = i + j
    if nunum > num:
    nunum = 0
    j = 0

    else:
    a = 0
    if num > j:
    b = 1
    nunum = j + k
    if nunum > num:
    nunum = 0
    k = 0
    else:
    b = 0
    if num > k:
    c = 1
    nunum = k + l
    if nunum > num:
    nunum = 0
    l = 0
    else:
    c = 0
    if num > l:
    d = 1
    nunum = l + m
    if nunum > num:
    nunum = 0
    m = 0
    else:
    d = 0
    if num > m:
    e = 1
    nunum = m + n
    if nunum > num:
    nunum = 0
    n = 0
    else:
    e = 0
    if num > n:
    f = 1
    nunum = n + o
    if nunum > num:
    nunum = 0
    o = 0
    else:
    f = 0
    if num > o:
    g = 1
    nunum = o + p
    if nunum > num:
    nunum = 0
    p = 0
    else:
    o = 0
    if num > p:
    h = 1
    nunum = p + o
    if nunum > num:
    nunum = 0
    else:
    h = 0
    print a,b,c,d,e,f,g,h

    now it will convert 255 ok but thats all
  • nevcnevc Posts: 6Member
    Here's a couple of ideas for the binary converter (I'm pretty new to python myself, so there's probably better ways). They are pretty self explanatory :-

    def MakeBinStr( SourceInt ):
    CurrInt = SourceInt

    OutStr = ''

    # repeatedly get right-most bit (remainder after division by 2)
    # and prepend to return string
    while CurrInt > 0 :
    # start while
    (CurrInt, BinDig) = divmod(CurrInt,2)
    OutStr = "%d%s" % (BinDig, OutStr)
    # end while

    return(OutStr)

    def MakeBinList( SourceNum ):
    CurrMask = 1L
    OutLst = []

    while 1:
    # start while
    OutLst.insert(0, int(((SourceNum & CurrMask) / CurrMask)))

    if CurrMask > SourceNum :
    break

    CurrMask = CurrMask << 1
    # end while

    return( OutLst )


    Neither of them handles negatives, but it shouldn't be too difficult make them do so.
  • nevcnevc Posts: 6Member
    I've added the style codes, as recommended by [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size], as well as a couple of comments explaining the 'while' loop in the second example.

    : Here's a couple of ideas for the binary converter (I'm pretty new to python myself, so there's probably better ways). They are pretty self explanatory :-
    [code]
    : def MakeBinStr( SourceInt ):
    : CurrInt = SourceInt
    :
    : OutStr = ''
    :
    : # repeatedly get right-most bit (remainder after division by 2)
    : # and prepend to return string
    : while CurrInt > 0 :
    : (CurrInt, BinDig) = divmod(CurrInt,2)
    : OutStr = "%d%s" % (BinDig, OutStr)
    :
    : return(OutStr)
    :
    : def MakeBinList( SourceNum ):
    : CurrMask = 1L
    : OutLst = []
    :
    : # use CurrMask (shifted left after each iteration) to deduce
    # bit values of SourceNum - inserting them into the return list
    : while 1:
    # bitwise and of SourceNum, CurrMask returns CurrMask or 0
    # divide by CurrMask to get bit value 1 or 0

    : OutLst.insert(0, int(((SourceNum & CurrMask) / CurrMask)))
    :
    : if CurrMask > SourceNum :
    : break
    :
    : CurrMask = CurrMask << 1
    :
    : return( OutLst )
    [/code]
    :
    : Neither of them handles negatives, but it shouldn't be too difficult make them do so.
    :
Sign In or Register to comment.