#๐ fonction that found the biggest number
40 messages ยท Page 1 of 1 (latest)
@placid shell
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
the code is :
def maxnum(a,b,c):
if a>=b and a>=c :
return a
elif b>=a and b>=c :
return b
else :
return c
a = input("number 1 : ")
b= input("number 2 : ")
c= input("number 3 : ")
print(maxnum(a,b,c))
!e
def maxnum(a,b,c):
if a>=b and a>=c :
return a
elif b>=a and b>=c :
return b
else :
return c
a,b,c = 1,2,3
print(maxnum(a,b,c))
@serene echo :white_check_mark: Your 3.12 eval job has completed with return code 0.
3
return max((a, b, c))
what makes you think it doesn't work?
presumably this is an assignment to help them learn how to code it themselves
what should this have returned?
3
it did
what test case did you try?
I just put 39,10 and 49
and what did it output?
I'm guessing it actually returned "39"
notice the quote marks
that means that it's a string
yes
you can compare strings in python with <, but they compare differently than numbers
!e
print( 2 < 11 )
print( "2" < "11" )
@serene echo :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | True
002 | False
strings are compared lexicographically, (like an extended alphabetical order)
ok I see but how can this impact a number
input always returns a string
if you want to use user input as something other than a string, you'll need to convert it yourself
exactly
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ fonction that found the biggest number