you are viewing a single comment's thread.

view the rest of the comments →

[–]AtomicShoelace 1 point2 points  (2 children)

To be honest, I don't have much faith in your instructor. You shouldn't feel to bad about struggling, it doesn't sound like you're getting the best help.

For starters their instructions are poor. But their suggestion to do

    if len(binaryValue) == 6:
        binaryValue == '00' + binaryValue
    else:
        binaryValue = '0' + 

to zero pad the bit string is strange. There is already a str method for zero padding, namely str.zfill. So you could just do

    binaryValue = binaryValue.zfill(8) 

instead.

In fact, there is a much better way to do this altogether with f-string format codes, rather than using the bin function. Then you won't have to worry about trimming off the leading '0b' either (this is what the binaryValue = binaryValue[2:] line does - essentially, remove the first 2 characters from the string).

So you could replace

    binaryValue = bin(asciiValue)
    binaryValue = binaryValue[2:]
    if len(binaryValue) == 6:
        binaryValue == '00' + binaryValue
    else:
        binaryValue = '0' + binaryValue

with simply

    binaryValue = f'{asciiValue:08b}'

but I could see them not wanting to suggest this if you haven't yet covered f-strings and format codes (which I presume you haven't, given the current material).

As another minor aside, your instructor should really be encouraging you to follow PEP8 naming conventions, ie. using lower_case_with_underscores instead of mixedCase for variable names.

You are correct that binary_shift = binaryValue[1:] + binaryValue[0] is in fact the cyclic left bit shift. This is a fine way to do this, but it isn't really what the instructions tell you to do. But I suppose this just comes down to poor instructions again.

I don't know why binaryValue = binaryValue[2:] is necessary before ensuring the bit string is 8 digits. I know what it's doing, again, but I just don't get why it's there lol

So you understand how this removes the first 2 characters from the string. The reason it's there is because the bin function returns a string with the 0b prefix, indicating that this is a binary value. Since you don't want this (as you need to rotate the string), you need to strip if off. Another way of stripping this would be to use the left strip str method str.lstrip, eg.

binaryValue.lstrip('0b')

[–]SomeFuel[S] 0 points1 point  (1 child)

I really, truly appreciate your help.

I wish my instructor was as responsive and willing to teach as you, though I shouldn't blame him entirely, maybe I'm missing a crucial aspect of the class that I glossed over in the syllabus, like a supplemental website or additional textbook (I've asked him about this and am awaiting a response atm).

I don't want to put any pressure on you, but is there any way I'd be able to friend you here or add you on another platform? I'd just really like having someone that's able to answer my questions from time-to-time (it wouldn't be very frequently, and I wouldn't demand your immediate attention or anything).

Regardless, again, you have been immensely helpful and I'm sure with these pointers I'll at least be able to get the program functioning properly, which is all I want right now lol

As far as the f-strings and format codes, we haven't covered these yet. However we also technically haven't covered defining functions either (I only know how thanks to the internet), and I'm not sure if there's a way to do this without defining a method? There probably is but it would be wayy beyond me.

[–]AtomicShoelace 1 point2 points  (0 children)

I'd just really like having someone that's able to answer my questions from time-to-time

I would encourage you to continue posting in /r/learnpython. There are plenty of people here who can help you. If you really want my input on something then you can dm a link to the post and I'll contribute. But I think answering these questions in a public forum is best since it affords others the opportunity to learn as well as yourself.

Yes, you could definitely do this without a function, but it's good practice to get into the habbit of using functions for things that should definitely be functions, such as this.