7 kyu
Basic Calculator
6,300 of 10,531TheDoctor
Description:
Write a function called calculate that takes 3 values. The first and third values are numbers. The second value is a character. If the character is "+" , "-", "*", or "/", the function will return the result of the corresponding mathematical function on the two numbers. If the string is not one of the specified characters, the function should return null (throw an ArgumentException
in C#).
calculate(2,"+", 4); //Should return 6
calculate(6,"-", 1.5); //Should return 4.5
calculate(-4,"*", 8); //Should return -32
calculate(49,"/", -7); //Should return -7
calculate(8,"m", 2); //Should return null
calculate(4,"/",0) //should return null
Keep in mind, you cannot divide by zero. If an attempt to divide by zero is made, return null (throw an ArgumentException
in C#)/(None in Python).
Fundamentals
Similar Kata:
Stats:
Created | Nov 27, 2013 |
Published | Nov 27, 2013 |
Warriors Trained | 14176 |
Total Skips | 654 |
Total Code Submissions | 29579 |
Total Times Completed | 10531 |
JavaScript Completions | 6300 |
Java Completions | 1331 |
C# Completions | 556 |
Python Completions | 2482 |
Total Stars | 115 |
% of votes with a positive feedback rating | 91% of 1475 |
Total "Very Satisfied" Votes | 1248 |
Total "Somewhat Satisfied" Votes | 196 |
Total "Not Satisfied" Votes | 31 |