#๐Ÿ”’ fonction that found the biggest number

40 messages ยท Page 1 of 1 (latest)

placid shell
#

works well but when the last variable is the biggest doesnt work

mild owlBOT
#

@placid shell

Python help channel opened

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.

placid shell
#

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))

serene echo
#

!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))
mild owlBOT
#

@serene echo :white_check_mark: Your 3.12 eval job has completed with return code 0.

3
minor flame
#

return max((a, b, c))

serene echo
#

what makes you think it doesn't work?

serene echo
placid shell
#

It works only when a and b are the biggest

#

but with c there is a problem

serene echo
placid shell
#

3

serene echo
#

what test case did you try?

placid shell
#

I just put 39,10 and 49

serene echo
#

and what did it output?

placid shell
#

39

#

but wait now it works

#

are you sure you didnt change anything ?

serene echo
#

I'm guessing it actually returned "39"

#

notice the quote marks

#

that means that it's a string

placid shell
#

yes

serene echo
#

you can compare strings in python with <, but they compare differently than numbers

#

!e

print( 2 < 11 )
print( "2" < "11" )
mild owlBOT
#

@serene echo :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | True
002 | False
serene echo
#

strings are compared lexicographically, (like an extended alphabetical order)

placid shell
#

ok I see but how can this impact a number

serene echo
#

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

placid shell
#

oooooh I understood

#

so I add int()

#

or float()

#

before input

serene echo
#

exactly

mild owlBOT
#
Python help channel closed

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