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

25th Nov 2017, 9:10 AM
Parikshit chettri
8 Réponses
+ 12
You don't need a "print", right? return ("The numbers are equal")
25th Nov 2017, 9:18 AM
Dev
Dev - avatar
+ 6
max() is easiest. But try not returning a print()
25th Nov 2017, 10:40 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
Or here's another: a=5 b=5 print(a) if a>b else print(b) #ternary operators
25th Nov 2017, 10:41 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 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))
25th Nov 2017, 9:55 AM
LISANGOLA BONDJALI CHRISTIAN
LISANGOLA BONDJALI CHRISTIAN - avatar
+ 1
max is a Python builtin function
25th Nov 2017, 9:15 AM
Nguyễn Hoàng Long
Nguyễn Hoàng Long - avatar
+ 1
to explain where None is coming from. see below, that is what you did: a= print(" some text") # a = None return a
25th Nov 2017, 9:22 AM
yuri
26th Nov 2017, 1:21 AM
Daniel
Daniel - avatar
+ 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))
26th Nov 2017, 1:23 AM
Daniel
Daniel - avatar