Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def expression_matter(a, b, c):
- # ensuring we have the right input // error handling
- if not isinstance(a, int) or not isinstance(b, int) or not isinstance(c,int):
- raise TypeError("sorry, only intergers allowed - try again")
- if not a >= 1 or not a <= 10:
- raise ValueError("sorry, a needs to be between 1 and 10")
- if not b >= 1 or not b <= 10:
- raise ValueError("sorry, b needs to be between 1 and 10")
- if not c >= 1 or not c <= 10:
- raise ValueError("sorry, c needs to be between 1 and 10")
- #list of possible calculations
- calc1 = [a * (b + c)]
- calc2 = [a * b * c]
- calc3 = [a + b * c]
- calc4 = [(a + b) * c]
- calc5 = [a + b + c]
- #computing the largest calculation
- highest_so_far = None
- for result in calc1:
- highest_so_far = result
- for result in calc2:
- if result >= highest_so_far:
- highest_so_far = result
- for result in calc3:
- if result >= highest_so_far:
- highest_so_far = result
- for result in calc4:
- if result >= highest_so_far:
- highest_so_far = result
- for result in calc5:
- if result >= highest_so_far:
- highest_so_far = result
- return highest_so_far
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement