简体   繁体   English

如何在python中检查多个条件

[英]how to check more than one condition in python

i want to make speech to math equation generator but i'm confused how to print more than one operators at a time here i use if-elif but in this case only one if statement is runing i want to run all statements which consists spoken operators我想对数学方程生成器发表演讲,但我很困惑如何在这里一次打印多个运算符 我使用 if-elif 但在这种情况下只有一个 if 语句正在运行 我想运行包含口语运算符的所有语句

here is my code这是我的代码

speech = r.recognize_google(audio)

            text = list(speech.split(" "))

            operators = ['plus','addition','multiply','into','minus','square','cube']

            sign = set(text) & set(operators)
            sign = ''.join(sign)
            #sign = 'into'

            if sign == 'into' or sign == 'multiply':
                si = 'x'
              #print(si)
            elif sign == 'square':
                si = '\u00b2'
              #print(si)
            elif sign == 'cube':
                si = '\u00b3'
              #print(si)
            elif sign == 'plus':
                si = '+'
              #print(si)

            if sign in text:
                tip = speech.replace(sign, si)
                tip = tip.replace(" ","")
                #print(tip)
                text_editor.insert(tk.END,tip)
                
            
        except Exception as e:
            print("Error: " + str(e))

when i speak "a plus b" then its print a+b but when i speak "a plus b into c" then output is not showing当我说“a plus b”然后它打印 a+b 但是当我说“a plus b into c”时输出没有显示

speech = r.recognize_google(audio)

text = list(speech.split(" "))

operators = ['plus', 'addition', 'multiply', 'into', 'minus', 'square', 'cube']
sign = set(text) & set(operators)

#sign = ''.join(sign)
# sign = 'into'

for s in sign:
    if s == 'into' or s == 'multiply':
        si = 'x'
        # print(si)
    elif s == 'square':
        si = '\u00b2'
        # print(si)
    elif s == 'cube':
        si = '\u00b3'
        # print(si)
    elif s == 'plus':
        si = '+'
        # print(si)

    if s in text:
        speech = speech.replace(s, si)
        speech = speech.replace(" ", "")
text_editor.insert(tk.END, speech)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM