__author__ = 'mk' def calculate(x,y,operator): switch(operator){ case 1: result = x + y; break; case 2: result = x - y; break; case 3: result = x * y; break; case 4: result = x / y; break; } return result """ simple calculate function with 4 main operator in this function I ask you to use if else instead of switch case :param x: the first number :param y: the second number :param operator: i define that it's a integer from 1 to 4: 1 is add, 2 is minus, 3 is multi and 4 is divide :return: result when after calculating x y with sign """ return 0 def main_function(): """ free edit this function as main method, but you have to commit change of this function to github :return: """ print calculate(1,2,3) main_function()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question