2016-11-03 4 views
-3

現在、Pythonでコードをプログラムしようとしていますが、返答が可能な回答のリストにある場合に返信します。 。Pythonエラー: "リストオブジェクトに属性がありません" .upper "

def responce(): 
    greetings = ["Hello","Hi","Nice to see you!","Greetings","How's it going?","How are you doing?","What's new?","How's your day going?","Hey!"] 
    print("\n") 
    reply = input(": ") 
    lenrep = len(reply) 
    tempstore = [] 
    for i in range(0,lenrep): 
     tempstore.append(i) 
     z = 0 
     while z < 9: 
      tempgreet = greetings[z] 
      if tempstore.upper() == tempgreet.upper(): 
       reply = "" 
       tempstore = [] 
       temprandno = random.randint(0,2) 
       addon = ["what do you want to know?", "what do you want to talk about?", " "] 
       addontext = addon[temprandno] 
       text(greet(), + " " + addontext) 
       z += 1 
     if i == " ": 
      tempstore = [] 

今、私の質問は、なぜそれがエラー

AttributeError: list object has no attribute 'upper' 

を思い付くんされており、それを動作させるために私のプログラムを修正する方法はありますか?

いかなるいただき、ありがとうございます応答。

+0

'tempstore'はリストであり、' upper() 'メソッドはありません。リスト内の単語を探すことを意味しましたか? – MooingRawr

+0

リストにはメソッド 'upper()'がありません: 'tempstore'はそのリストです。それは整数のリストなので、それについて大文字にしたいものは不明です。 – Evert

+0

はい私はリストMooingRawrの単語を探すことを意味した –

答えて

2

ヒント:

greetingsInUpCases = [elem.upper() for elem in greetings ] 

大文字への挨拶]リストのすべての文字列を変換し、replyは、現在のリストにある場合の式

reply.upper() in greetingsInUpCases 

はあなたが決めることができifステートメントで使用することができます:

if reply.upper() in greetingsInUpCases: 
+0

ありがとう、これはそれを修正するのに役立ち、それは最終的に動作し、upvoted持っているが、私の評判のため表示されません。 –

関連する問題