Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1.  
  2. def expression_matter(a, b, c):
  3.  
  4.     # ensuring we have the right input // error handling
  5.  
  6.     if not isinstance(a, int) or not isinstance(b, int) or not isinstance(c,int):
  7.         raise TypeError("sorry, only intergers allowed - try again")
  8.     if not a >= 1 or not a <= 10:
  9.         raise ValueError("sorry, a needs to be between 1 and 10")
  10.     if not b >= 1 or not b <= 10:
  11.         raise ValueError("sorry, b needs to be between 1 and 10")
  12.     if not c >= 1 or not c <= 10:
  13.         raise ValueError("sorry, c needs to be between 1 and 10")
  14.  
  15.     #list of possible calculations
  16.     calc1 = [a * (b + c)]
  17.     calc2  = [a * b * c]
  18.     calc3 = [a + b * c]
  19.     calc4 = [(a + b) * c]
  20.     calc5 = [a + b + c]
  21.  
  22.     #computing the largest calculation
  23.  
  24.     highest_so_far = None    
  25.     for result in calc1:
  26.         highest_so_far = result
  27.        
  28.     for result in calc2:
  29.         if result >= highest_so_far:
  30.             highest_so_far = result
  31.          
  32.     for result in calc3:
  33.          if result >= highest_so_far:
  34.             highest_so_far = result
  35.          
  36.     for result in calc4:
  37.         if result >= highest_so_far:
  38.             highest_so_far = result          
  39.    
  40.     for result in calc5:
  41.         if result >= highest_so_far:
  42.             highest_so_far = result
  43.  
  44.     return highest_so_far
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement