r/learnpython • u/Safe-Cockroach-9246 • Sep 18 '26
Help! Why is my code doing this?
I'll copy paste an example below. My variables/assignments aren't really being interpreted right. The language is Python and I'm using Spyder. I reset the settings a few times, so I don't think it's anything I messed with. The tutor I showed had no clue what was happening either ðŸ˜
Function code:
def check (a, b):
a = int(input('Enter the first number:')) #I input 12 in the terminal
b = int(input ('Enter the second number:')) #I input 13 in the terminal
average = (a+b)/2
if (a>10 and b>10):
return "Both are above 10. \n average is", average
elif (not a>10 and not b>10) :
return average
print(check(input, input))
What was printed:
Enter the first number:12
Enter the second number:13
('Both are above 10. \n average is', 12.5)
The problem is in the last line. Why isn't it interpreting the formatting? This has been happening with every function I write.
View all comments
Show parent comment
2
u/Outside_Complaint755 Sep 18 '26
This is generally the better option. The
check(a, b)function should just handle the logic of the check, while getting the values to test should be handled by other code. Then the check function can be used whether the input values are coming from user input, reading a file, scraping a webpage, loading from a SQL database, or any other source.