Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

get operator as input in python

num = str(input("Enter a number greater than 1: "))

oper = str(input("Choose a math operation (+, -, *, /, %, //): "))
if oper in ["+", "-", "*", "/", "%", "//"]:
    for i in range(1, 11):
        operation = num + oper + str(i) #Combine the string that is the operation
        print("{} {} {} = {}".format(num,oper,str(i),eval(operation)))
else: #if it is not in our approved items
    print("Operation not supported.")
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #operator #input #python
ADD COMMENT
Topic
Name
8+2 =