Answers for "get operator as input in python"

0

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')
Posted by: Guest on October-13-2021
0

get operator as input in python

def operation(number1, number2, operator):
    if operator == '+':
        return number1 + number2
    elif operator == '-':
        return number1 - number2
Posted by: Guest on October-13-2021
0

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.")
Posted by: Guest on October-13-2021

Python Answers by Framework

Browse Popular Code Answers by Language