我正在嘗試在Python中製作一個腳本,它將結合西班牙語動詞。這是我第一次使用Python編寫腳本,所以這可能是一個簡單的錯誤。當我運行該腳本,我輸入 「喲特納」,並收到一個錯誤:NameError:名稱''未定義
Traceback (most recent call last): File "", line 13, in File "", line 1, in NameError: name 'yo' is not defined
多見於:http://pythonfiddle.com/#sthash.bqGWCZsu.dpuf
# Input pronoun and verb for conjugation. text = raw_input() splitText = text.split(' ') conjugateForm = eval(splitText[0]) infinitiveVerb = eval(splitText[1]) # Set the pronouns to item values in the list. yo = 0 nosotros = 1 tu = 2 el = 3 ella = 3 usted = 3 # Conjugations of the verbs. tener = ["tengo", "tenemos", "tienes", "tiene", "tienen"] ser = ["soy", "somos", "eres", "es", "son"] estar = ["estoy", "estamos", "estas", "esta", "estan"] # List of all of the infinitive verbs being used. Implemented in the following "if" statement. infinitiveVerbs = [tener, ser, estar] # Check to make sure the infinitive is in the dictionary, if so conjugate the verb and print. if infinitiveVerb in infinitiveVerbs: print("Your conjugated verb is: " + infinitiveVerb[conjugateForm])
此外,'eval'是一個安全風險。考慮一下,如果用戶輸入'os.system('/ home/hack.sh')'作爲程序的輸入,會發生什麼。 – tripleee