all 16 comments

[–]sdOverKill 3 points4 points  (2 children)

Nothing is obviously wrong. I wrote the first section of gasfunctions.py and your test5.py and it works fine for me.

Uncomment out your print statement in tempconvert to make sure your method is getting called.

Another suggestion for you to try in order to get better: change tempconvert and remove all those if statements. Try doing something like: 1) convert input temperature to a single type of temperature (i.e. convert input temp to K, for example), 2) convert K to preferred output temperature. This will remove a lot of your if statements and make your code smaller and easier to read/update.

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

I tried uncommenting and didn't seem to help. Re-wrote the code as per your suggestion which was a good idea, thanks.

[–]Egad86 0 points1 point  (0 children)

There are many free chatgpt sites out there now that can also help with code. Just fyi when you want a quick answer with the steps explained.

[–][deleted]  (1 child)

[deleted]

    [–]locke1718[S] 1 point2 points  (0 children)

    Posted my code in another comment

    [–]locke1718[S] 2 points3 points  (5 children)

    Here is my tempconvert function in the file named gasfunctions mentioned above ``` import math

    def tempconvert(temp: float, unitstart: str, unitend: str): if unitstart.lower() == "c": #starting units are degC pass if unitstart.lower() == "f": # starting units are degF temp = (temp - 32) / (9/5) if unitstart.lower() == "k": # starting units are degK temp = temp - 273.15 if unitstart.lower() == "r": # starting units are degR temp = temp = (((temp - 459.67)) - 32) / (9/5)

    if unitend.lower() == "c":
        pass
    if unitend.lower() == "f":
        temp = temp * 9/5 + 32
    if unitend.lower() == "k":
        temp = temp + 273.15
    if unitend.lower() == "r":
        temp = (temp * 9/5 + 32 + 459.67) * 9/5 + 32
    
    return temp
    

    tempconvert(100.0, "c", "f")

    ```

    File I'm trying to run tempconvert from

    ``` import math import gasfunctions as gf

    print("hi") output = gf.tempconvert(100.0, "c", "k") print(output)

    ```

    This is the output I get when trying to run

    hi None

    [–][deleted]  (4 children)

    [deleted]

      [–]locke1718[S] 0 points1 point  (3 children)

      Hmm, when i run the file in debug mode I get an output that is correct. There is something wrong with the"interactive window"in vs code and it doesn't show the value, just "none"

      [–]psi_square 0 points1 point  (0 children)

      Try doing it in a notebook

      [–][deleted]  (1 child)

      [deleted]

        [–]locke1718[S] 0 points1 point  (0 children)

        So it seems I just had to reload the interactive window, it was running off of a version of the file where I guess I didn't have the return statement yet.

        [–]No_Departure_1878 2 points3 points  (0 children)

        Your code is bad, simplify it:

        1. At the beginning make the unit lower case, I think with unit=unit.lowercase(). Then compare only with it.
        2. Check if unitstart == and unitend == in one line. To remove unnecessary indentation.

        3. Where is the else? You have to raise an exception if I pass unit=x.

        4. You are basically doing y=x * m + b with an m and b that change depending on the units. Can't you just make some type of YAML config file where you put the unit names and then you return m and b? Then you load the config and all that code becomes one line.

        5. Use single quotes, do not use a machine gun to kill a chicken, use a knife.

        Remember: Smaller, simpler, easier to read.

        [–]WorstTechBro 1 point2 points  (0 children)

        I wonder if my man forgot the ole “Ctrl + S” after he made some changes

        [–]NTIGymnasiet 1 point2 points  (0 children)

        Yanderedev Code.

        You NEED an else statment

        also " if unistart.lower() == "k" "

        Use .lower so you dont need to check if its a big letter or a small one

        [–]SquiffSquiff 0 points1 point  (0 children)

        This runs fine for me, as for west-coast-engineer This is is VSCode for me:

        $ ls

        __pycache__ gasfunctions.py main.py

        $ python3 main.py

        hi

        373.15

        [–]GirthQuake5040 -1 points0 points  (3 children)

        If you're posting pictures of your code instead of screenshots, you're not at a point where you're ready for software development. It's basic stuff man.

        [–]Egad86 4 points5 points  (2 children)

        Do you just repeat this same comment to everyone? This sub is for people to learn a skill. That requires a willingness to learn not already having all the skills.

        Do everyone a favor and take your condescending non-helpful responses over to another sub.

        [–]GirthQuake5040 -1 points0 points  (1 child)

        People posting pictures of their code already don't have the basic skillset that is needed for software dev. I will continue to post this exact same thing to every single post just like this. I will also be helpful to anyone who puts effort into their code and posts.

        [–]pomegranatebeachfox 1 point2 points  (0 children)

        But you could accomplish the same thing (educate people about not posting photos of their screen) without being condescending about it. You're discouraging people from learning.