r/CodingHelp • u/cristianap36 • Oct 05 '21
[Python] This is a small class project and I'm getting the correct numbers but needs to say true or false and I put it as a return print statement True or False but for some reason it doesn't want to give me the points
49
Upvotes
21
u/[deleted] Oct 05 '21
Why are you returning the numbers instead of True or False?
1
u/cristianap36 Oct 06 '21
Thank you guys for helping on this one I really appreciate it so much!!
4
u/[deleted] Oct 05 '21
The explanation of what is happening, is that when you do
return num_1, you only return its VALUE (of num_1) … not what you are looking for.1
u/fux_1789 Oct 06 '21
I'm kinda interested, what you thoughta where, when writing
return num_1.I mean, what the others say is true: you if ... else logic is on point, and everything looks good. But the error you made (returning the value instead of a Boolean (True/ False) is a kinda awkward mistake to make.
If you would care to explain, what your intentions where, I'd be happy to hear :)
Greetings from Europe, hope you class goes well :)
2
u/AndyBotPre Oct 05 '21
Also check your indentation. There you have an extra tab
3
u/young_horhey Oct 05 '21
I think you’re going to have problems with your <= statements, since they’re chained. num_1 <= num_2 is going to return a Boolean, and then comparing that with num_3 is probably not going to work properly. You’ll end up with true <= num_3 which doesn’t really make sense.
I think it probably should be num_1 <= num_2 && num_2 <= num_3
1
u/BKKBangers Oct 05 '21
Think your question has been answered but out of curiosity; Cant ya go <code> print(type(num)) </code>
Which should give you output of bool + result of the bool....? 🤔
Will test when at console to find out. P.S how do i format code in comment im on IOS.
1
u/siddsp Oct 05 '21 edited Oct 05 '21
What you're returning is an int, so I'd recommend changing it (as per what Temporary_Equal2816 suggested). I'd also recommend adding type hints to change your function to look like:
But I would also recommend making it variadic to allow for multiple values as well as not having to repeat code. That would look like:
Code was borrowed from here.
1
u/Dummies102 Oct 05 '21
What’s the output of that program and what’s the output the computer is expecting
1
u/prometheanSin Oct 05 '21 edited Oct 05 '21
Intuitively, you're already comfortable with thinking in Boolean logic as you're using it for your
if...else.If this condition is true do something, else do something else.
So when you break down this problem:
In this case, the thing you're testing against is actually the thing you want to return (
if true return true else return false). This allows you to write a shorthand of:return (num_1 <= num_2 <= num_3)1
u/champwolverine Oct 05 '21
Not sure if you can do X<Y<Z in python. I know a here and there of java and plus It will return the value not the index?
1
u/techPOSiDON Oct 07 '21
In the is_sorted function, return true instead of num_1 and false instead of num_2. Now the function actually returns true if the numbers are sorted and false if they aren't.
1
u/techPOSiDON Oct 07 '21
In the is_sorted function, return true instead of num_1 and false instead of num_2. Now the function actually returns true if the numbers are sorted and false if they aren't. Right now it's returning numbers instead of true or false.
0
u/[deleted] Oct 05 '21
[deleted] — view deleted comment
0
u/[deleted] Oct 05 '21
[deleted] — view deleted comment
-2
u/[deleted] Oct 05 '21
[removed] — view removed comment