2017-02-21 10 views
0

構文エラーが発生しているので、このコードに問題があります。私は異なる挨拶のリストを作成しましたが、私はそれを24行目で思い出すことができませんでした。感謝:)+: 'NoneType'および 'str'のサポートされていないオペランドタイプtkinterエラー

import pyttsx 
import sklearn 
import random 

speech_engine = pyttsx.init('sapi5') # see  http://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init 
speech_engine.setProperty('rate', 150) 
def Hello(): 

    words = [line.strip() for line in open('Hello.txt')] 
    speak(random.choice(words)) 




def speak(text): 
    speech_engine.say(text) 
speech_engine.runAndWait() 


intro=(Hello()) 

Greeting=input(speak("What is your name")) 

Account=input(speak(intro + Greeting + ", Would you like to Log in or create an account")) 


if Account==("Create An Account") or Account==("Create An Account") or Account==("create an account"): 
     Password=input(speak("What is the password going to be for your account")) 
     text_file = open("Password.txt", "a") 
     text_file.write("|   "+ Greeting +"     |   "+ Password +"   |\n") 
     text_file.close() 

答えて

2

あなたの関数Hello()return何でも、それは暗黙的にイントロ=なし、Noneを返しませんので。これで、Noneに文字列を "追加"しようとしました。これはまさにエラーメッセージの内容です。

Hello()関数を呼び出してユーザーを迎えたい場合は、戻り値を代入せずにHello()を呼び出すだけです。とにかくNoneなので、それをinput(...)ステートメントに含める明確な理由はありません。

EDIT:

考慮にあなたのコメントを取って、私はあなたがあなたの関数を変更するお勧め:

def Hello(): 
    words = [line.strip() for line in open('Hello.txt')] 
    return random.choice(words) 
+0

この問題を解決する方法はありますか?申し訳ありませんが、これはかなり新しいです –

+0

'intro + Greeting +" ... "'であなたが達成しようとするものによって異なります。今、 'intro +'部分を削除することで、その特定の問題を解決できるでしょう。 –

+0

私はそれが私が必要とする部分であるので、毎回 "こんにちは"とは言いません。 –

関連する問題