在Python中,我的函数不返回值

时间:2019-12-27 15:51:11

标签: python python-3.x comparison

运行程序时,它没有向我返回输入的值num1num2

有人可以告诉我我在做什么错吗?

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

print('Lists of operations: ')
print('1. add')
print('2. subtract')
print('3. multiply')
print('4. divide')

operations = int(input('Select an operation (1/2/3/4): '))

num1 = float(input('Enter a number: '))
num2 = float(input('Enter a number: '))
# Functions aren't returning values
if '1' == operations:
    print(num1,'+',num2,'equals'+ add(num1, num2))
# Functions aren't returning values
elif '2' == operations:
    print(num1,'-',num2,'equals', subtract(num1, num2))
# Functions aren't returning values
elif '3' == operations:
    print(num1,'*',num2,'equals', multiply(num1, num2))
# Functions aren't returning values
elif '4' == operations:
    print(num1,'/',num2,'equals', divide(num1, num2))

1 个答案:

答案 0 :(得分:2)

您正在将整数与字符串进行比较:

df[df[('c', 'a')] > 0]

   c  b
   a   
0  1  4
1  2  5
2  3  6

df[df['b'] > 0]

   c  b
   a   
0  1  4
1  2  5
2  3  6

使用if '1' == operations: 代替1,其他数字也一样:

'1'