def add(x,y): return x + y def subtract(x,y): return x - y def multiply(x,y): return x * y def divide(x,y): return x / y def modulus(x,y): return x % y def power(x,y): return x ** y # take input from the user print("Select operation.") print("1.Add") print("2.Subtract") print("3.Multiply") print("4.Divide") print("5.Modulus") print("6.Power") # Accept input from the user - the operation to perform choice = raw_input("Enter choice(1/2/3/4):") # Accept two inputs and perform convert from string to integer type num1 = int(raw_input("Enter first number: ")) num2 = int(raw_input("Enter second number: ")) # Check to see of the user input was equal 1 if choice == '1': print(num1,"+",num2,"=", add(num1,num2)) elif choice == '2': print(num1,"-",num2,"=", subtract(num1,num2)) elif choice == '3': print(num1,"*",num2,"=", multiply(num1,num2)) elif choice == '4': print(num1,"/",num2,"=", divide(num1,num2)) elif choice == '5': print(num1,"%",num2,"=", modulus(num1,num2)) elif choice == '6': print(num1,"**",num2,"=", power(num1,num2))
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