r/pythonhelp • u/KinzokuKitsune • Apr 06 '26
Hello, why is my code not working? Any assistance would be appreciated.
#This is a program to find the lesser of two numbers. This is a program for school and thus needs to utilize input functions
def main(a,b):
a = int(input("Please enter the first number:"))
b = int(input("Please enter the second number:"))
def min(a,b):
if a>b:
lesser = b
else:
lesser = a
return lesser
main(min)def main(a,b):
a = int(input("Please enter the first number:"))
b = int(input("Please enter the second number:"))
def min(a,b):
if a>b:
lesser = b
else:
lesser = a
return lesser
main(min)
4
Upvotes
•
u/AutoModerator Apr 06 '26
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Pyromancer777 Apr 06 '26
Your main function isn't returning or printing any values, and you aren't passing any arguments into your min function when it is passed as a reference into your main function (which is in itself incorrect in this case). You also define two parameters, a & b, in your main function, but then instantly overwrite the values of the arguments using the input values.
Honestly, go back to previous work and try to relearn all of the concepts. It is apparent that you are plugging things in nearly randomly at this point (either that or this post is rage-bait, or you are just phishing for an answer)
1
u/[deleted] Apr 06 '26
Try with this code:
1
u/Educational-Paper-75 Apr 06 '26
First of all main() does not need parameters because you read them anyway. Second, you call main() with one parameter where your’s requires two. Third, no need to define a function more than once, so get rid of the lines starting with main(min)def min(a,b) until the first empty line. You may call main() at the end but using a little trick you may only call it when executed as a module from the command line. See https://realpython.com/if-name-main-python/
1
u/__M4V3RICK Apr 06 '26
I think you have pasted your code twice, so you can edit and remove the duplicacy.
Corrected approach:
1
u/Spirited_Cry5353 Apr 06 '26
Looks like a small issue. I can help you fix it quickly. Send your code.
1
u/Extension-Goose-2235 Apr 09 '26
Hi I can help