exceptions_allowed - if True, will return exception instead of 0 when error occurs. Default is False."""
if not isinstance(sign, str):
if not exceptions_allowed: return 0
else: raise TypeError('Type of the sign must be string.')
if not isinstance(n1, (int, float, complex)):
if not exceptions_allowed: return 0
else: raise TypeError('Type of the first number must be int, float or complex.')
if not isinstance(n2, (int, float, complex)):
if not exceptions_allowed: return 0
else: raise TypeError('Type of the second number must be int, float or complex.')
if sign not in "+-*/**%":
if not exceptions_allowed: return 0
else: raise TypeError('Sign must be +, -, *, /, ** or %.')
if sign == "/" and n2 == 0:
if not exceptions_allowed: return float('inf') #mathematically this is better, than x/0=0
else: raise ZeroDivisionError('Can't divide by zero.')
return eval(str(n1) + sign + str(n2)) #using universal and optimized, but dangerous and bugged solution
PS C:\Users\giorg>
PS C:\Users\giorg> PS C:\Users\giorg> }component {
function add(required a, required b) {
return a + b;
}This is italic
This is also italicThis is bold
This is bold toohere, italic and bold
here, italic and bold
You can have bold in italic
test.assert_equals(calculator("/", 1, 0), float('inf')) test.assert_equals(calculator("+", 42, 11), 53) test.assert_equals(calculator("-", 6, 50), -44) test.assert_equals(calculator("/", 32, 2, exceptions_allowed=True), 16) test.assert_equals(calculator("*", 25, 5), 125) test.assert_equals(calculator(123, 2), 0) test.assert_equals(calculator('%', 11, 5), 1)
test.assert_equals(calculator("/", 1, 0), float('inf')) test.assert_equals(calculator("+", 42, 11), 53) test.assert_equals(calculator("-", 6, 50), -44) test.assert_equals(calculator("/", 32, 2, exceptions_allowed=True), 16) test.assert_equals(calculator("*", 25, 5), 125) test.assert_equals(calculator(123, 2), 0) test.assert_equals(calculator('%', 11, 5), 1) PS C:\Users\giorg> PS C:\Users\giorg> PS C:\Users\giorg> component { >> >> function add(required a, required b) { >> >> return a + b; >> >> }_This is italic_ >> *This is also italic* >> >> __This is bold__ >> **This is bold too** >> >> ___here, italic and bold___ >> ***here, italic and bold*** >> *You can have **bold** in italic*
- test.assert_equals(calculator("/", 1, 0), float('inf'))
- test.assert_equals(calculator("+", 42, 11), 53)
- test.assert_equals(calculator("-", 6, 50), -44)
- test.assert_equals(calculator("/", 32, 2, exceptions_allowed=True), 16)
- test.assert_equals(calculator("*", 25, 5), 125)
- test.assert_equals(calculator(123, 2), 0)
- test.assert_equals(calculator('%', 11, 5), 1)
- PS C:\Users\giorg>
- PS C:\Users\giorg> PS C:\Users\giorg> component {
- >> >> function add(required a, required b) {
- >> >> return a + b;
- >> >> }_This is italic_
- >> *This is also italic*
- >>
- >> __This is bold__
- >> **This is bold too**
- >>
- >> ___here, italic and bold___
- >> ***here, italic and bold***
- >> *You can have **bold** in italic*