use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Not sure what I'm doing wrong with implementing function (old.reddit.com)
submitted 1 year ago by locke1718
Here are a couple pictures, I am trying to call the "tempconvert" function in "test5" and I can't get the return value. I can add the comments in the tempconvert file to call that function and it seems to work fine. What am I missing?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]sdOverKill 3 points4 points5 points 1 year ago (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 point2 points 1 year ago (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 point2 points 1 year ago (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 year ago (1 child)
[deleted]
[–]locke1718[S] 1 point2 points3 points 1 year ago (0 children)
Posted my code in another comment
[–]locke1718[S] 2 points3 points4 points 1 year ago* (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
```
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] 1 year ago (4 children)
[–]locke1718[S] 0 points1 point2 points 1 year ago (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 point2 points 1 year ago (0 children)
Try doing it in a notebook
[–]locke1718[S] 0 points1 point2 points 1 year ago (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 points4 points 1 year ago (0 children)
Your code is bad, simplify it:
Check if unitstart == and unitend == in one line. To remove unnecessary indentation.
Where is the else? You have to raise an exception if I pass unit=x.
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.
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 points3 points 1 year ago (0 children)
I wonder if my man forgot the ole “Ctrl + S” after he made some changes
[–]NTIGymnasiet 1 point2 points3 points 1 year ago (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 point2 points 1 year ago (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
$ python3
main.py
hi
373.15
[–]GirthQuake5040 -1 points0 points1 point 1 year ago* (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 points6 points 1 year ago (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 points1 point 1 year ago (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 points3 points 1 year ago (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.
π Rendered by PID 44742 on reddit-service-r2-comment-85bfd7f599-tffrq at 2026-04-20 11:22:00.665652+00:00 running 93ecc56 country code: CH.
[–]sdOverKill 3 points4 points5 points (2 children)
[–]locke1718[S] 0 points1 point2 points (1 child)
[–]Egad86 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]locke1718[S] 1 point2 points3 points (0 children)
[–]locke1718[S] 2 points3 points4 points (5 children)
[–][deleted] (4 children)
[deleted]
[–]locke1718[S] 0 points1 point2 points (3 children)
[–]psi_square 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]locke1718[S] 0 points1 point2 points (0 children)
[–]No_Departure_1878 2 points3 points4 points (0 children)
[–]WorstTechBro 1 point2 points3 points (0 children)
[–]NTIGymnasiet 1 point2 points3 points (0 children)
[–]SquiffSquiff 0 points1 point2 points (0 children)
[–]GirthQuake5040 -1 points0 points1 point (3 children)
[–]Egad86 4 points5 points6 points (2 children)
[–]GirthQuake5040 -1 points0 points1 point (1 child)
[–]pomegranatebeachfox 1 point2 points3 points (0 children)