Search
 
SCRIPT & CODE EXAMPLE
 

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.")
Comment

get operator as input in python

def operation(number1, number2, operator):
    if operator == '+':
        return number1 + number2
    elif operator == '-':
        return number1 - number2
Comment

get operator as input in python

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

oper = raw_input("Choose a math operation (+, -, *): ")
for i in range(1, 11):
    if oper == '+':
        print(num, oper, i, '=', num + i)
    elif oper == '-':
        print(num, oper, i, '=', num - i)
    elif oper == '*':
        print(num, oper, i, '=', num * i)
    else:
        print('operator is not supported')
Comment

PREVIOUS NEXT
Code Example
Python :: make_response is not defined django 
Python :: generate n different colors matplotlib 
Python :: python do while loop 
Python :: zip a directory in python 
Python :: np.arange in python 
Python :: python get last item in a list 
Python :: get column index pandas 
Python :: Word2Vec 4.0 Gensim model python dataframe 
Python :: pandas: split string, and count values? 
Python :: plt delete space before axis 
Python :: python round 1 decimal place 
Python :: how to set pandas dataframe as global 
Python :: python typecast 
Python :: pytthon how many fridays´ between two dates 
Python :: how to get the most common number in python 
Python :: python for loop index 
Python :: how to read .xlsx file in python 
Python :: python multiple conditions in dataframe column values 
Python :: load data python 
Python :: how to access items in a list 
Python :: python capitalize the entire string 
Python :: Local to ISO 8601: 
Python :: python between inheritance and composition 
Python :: merge 2 dataframes in python 
Python :: login url 
Python :: check if string match regex python 
Python :: __dict__ python? 
Python :: else if python 
Python :: how to convert pandas price column to integer 
Python :: python extract all characters from string before a character 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =