+ 1
A programe to find the maximum of two numbers using python
#The problem is when the given numbers are equal , the output looks like :"The...equal" and additional "None" #How is it that this "None" is appearing def max(x,y): if x==y: return print("The numbers are equal") if x>=y: return (x) else: if y>=x: return(y) print(max(5,5))
8 Réponses
+ 12
You don't need a "print", right?
return ("The numbers are equal")
+ 6
max() is easiest.
But try not returning a print()
+ 5
Or here's another:
a=5
b=5
print(a) if a>b else print(b) #ternary operators
+ 2
Just call the max() methode by passing as parameters yours numbers.
Eg1. max(2,5,4,10) #=>Will return 10
Eg2: n1=23
n2=12
max(n1,n2)#=>returns 23
And if you want to print the result using the print function: print(max(n1,n2))
+ 1
max is a Python builtin function
+ 1
to explain where None is coming from. see below, that is what you did:
a= print(" some text") # a = None
return a
+ 1
If you want:
https://code.sololearn.com/cNXV38z00Aba/?ref=app
+ 1
or try:
def maxi(x,y):
if x==y:
return print("The numbers are equal")
elif x>=y:
return (x)
else:
return(y)
print(maxi(5,5))