运行python程序时出现Elif错误

时间:2020-07-26 00:57:32

标签: python

SyntaxError: invalid syntax
PS C:\Users\indu praksh\Desktop\Summer\JARVIS> & "C:/Users/indu praksh/AppData/Local/Programs/Python/Python38/python.exe" "c:/Users/indu praksh/Desktop/Summer/JARVIS/jarvis.py"
    elif hour>=12 and hour<18:

1 个答案:

答案 0 :(得分:0)

您的代码: 得到它了。您在runandwait()中丢失了()。现在开始运行,我可以听到有人讲话。

import pyttsx3
import datetime

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
#print(voices[0].id)
engine.setProperty('voice',voices[0].id)

def speak(audio):
    engine.say(audio)
    engine.runAndWait()  ## ERROR FIXED

def wishme():
    hour = int(datetime.datetime.now().hour )
    if hour>=0 and hour<12:
        speak("good morning!")
    elif hour>=12 and hour<18:
        speak("Good afternoon!")
    else:
        speak("good evening!")

speak("I am jarvis sir,how may i help you")