首页 > 解决方案 > python 3错误不支持&的操作数类型:'str'和'str'

问题描述

def temperature():
    A=str(input("enter your unit"))
    B=str(input("enter your conversion unit"))
    C=int(input("enter temperature"))
    if A=="c"  & B=="f":
        print("your temp in fahrenheit is",C*9/5+32,"f")
    elif A=="c" & B=="k":
        print("your temp in kelvin is",C+273.15,"k")
    elif A=="f" & B=="c":
        print("your temp in celsius is",C-32*5/9,"c")
    elif A=="f" & B=="k":
        print("your temp in kelvin is",C+459.67,"k")
    elif A=="k" & B=="c":
        print("your temp in celsius is",C+273.15,"c")
    elif A=="k" & B=="f":
        print("your temp in fahrenheit is",C-273.15*9/5+32,"f")
    else:
        print("not valid")

temperature()

当我运行此代码时,它会引发以下错误:

File "D:\PYTHON PROGRAMS\if and else\temperature.py", line 20, in <module>
    temperature()  
File "D:\PYTHON PROGRAMS\if and else\temperature.py", line 5, in temperature
    if A=="c"  & B=="f":

TypeError: unsupported operand type(s) for &: 'str' and 'str'

请帮我解决一下这个。

标签: python-3.x

解决方案



推荐阅读