变量内的操作

时间:2017-08-20 23:03:04

标签: python

我想创建一个python脚本,使用2个操作找到最大可能的输出。问题是它在第2行到最后一行有一个语法错误,在那里b。我该如何解决?

x = 0
a = int(input("1st number:")) 
c = int(input("2nd number:" )) 
e = int(input("3rd number:" ))
for i in range(4):
    if i == 0:
        b = "+" 
    elif i == 1: 
        b = "-"
    elif i == 2:    
        b = "/"
    else:
        b = "*" 
    for j in range(4):
        if j == 0:
            d = "+" 
        elif j == 1: 
            d = "-" 
        elif j == 2:    
            d = "/" 
        else:
            d = "*" 
        k = a b c d e
        print(k) 

2 个答案:

答案 0 :(得分:-1)

如果你只是在一行上的变量a到e,你不能用逗号分隔它们并打电话给Print吗?

Print a,b,c,d,e

答案 1 :(得分:-2)

k = a b c d e会给您错误,因为这是不允许的。你可以这样做:

if b == "+" and d == "+":
    k = a + c + e
elif b == "+" and d == "-":
    k = a + c - e

等等。