Advertisement
Acer1968

Max from two numbers in range, or zero

Jul 19th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. def maxfromrange(a,b,limitmin=10,limitmax=20): #limit inclusive in range
  2.   atest=a in range(limitmin, limitmax+1)
  3.   btest=b in range (limitmin, limitmax+1)
  4.   if atest and btest:
  5.     return(a if a>b else b)
  6.   elif not atest and not btest:
  7.     return(0)
  8.   else:
  9.     return(a*atest + b*btest)
  10.  
  11. print (maxfromrange(11,19))
  12. print (maxfromrange(19,11))
  13. print (maxfromrange(11,9))
  14. print (maxfromrange(11,21))
  15. print (maxfromrange(9,21))
  16. print (maxfromrange(10,21))
  17. print (maxfromrange(21,10))
  18. print (maxfromrange(23,10))
  19. print (maxfromrange(20,10))
  20. print (maxfromrange(21,3,1))
  21. print (maxfromrange(21,3,1,25))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement