私のリストにユーザー入力を書き込むのに問題がありますここで何が間違っていますか?これは、私が書いているアドレス帳プログラムです。割り当ては、forループまたはwhileループを使用して適切なリストにユーザー入力データを格納する並列リストを作成することです。プログラムには、コードの最下部に表示される検索機能も必要です。私の問題は、私のリストにデータを保存するプログラムを取得することです。残念ながらリストは私に何度も苦労しているものです。どれだけ多くの研究をしても、私の頭の中で私の頭を包んでいるようです。実行中の問題は、lastnameとfirstnameを私の名前リストに書き込もうとすると、append.data関数です。私は何を間違えているのですか?ユーザー入力を適切なリストに追加するアドレス帳プログラムを作成しようとしています
#NICHOLAS SHAFFER
#5/11/2016
#MYADDRESSBOOK
def menu():
index = 0
size = 100
count = 0
answer = raw_input("Are You Creating An Entry [Press 1] \nOr Are You Searching An Entry [Press 2] ")
if answer == "1" :
print ("This is where we create")
append_data(index, size, count)
elif answer == "2" :
print ("this is where we search")
search_database()
name[size]
phone[size]
addresss[size]
# IF we are creating
def append_data(index, size, count):
# collect information
for index in range(0, 100):
optOut = 'no'
while optOut == 'no':
lastname[count] = raw_input("What is the persons last name? ")
firstname[count] = raw_input("What is the persons first name? ")
phone[count] = raw_input("What id the persons phone number? ")
address[count] = raw_input("What is the persons address? ")
count = count + 1
print 'Would you like to create another entry?'
optOut = raw_input('Would you like to create another entry? [ENTER YES OR NO]:')
if optOut == 'yes':
menu()
#create string to print to file
#print temp1
#print (firstname + " " + lastname + ", " + phone + ", " + email + ", " + address)
print listName[index]
print listPhone[index]
print listAddress[index]
print 'file has been added to your addressbook sucessfuly'
menu()
# SEARCHING FOR A RECORD
def search_database():
searchcriteria = raw_input("Enter your search Criteria, name? phone, or address etc ")
print searchcriteria
if searchcriteria == "name":
temp1 = open(listName[lastname, firstname],"r")
print temp1
if searchcriteria == "phone":
temp1 = open(listPhone[0], "r")
print temp1
if searchcriteria == "address":
temp1 = open(listAddress[0], "r")
print temp1
else:
print "sorry you must enter a valid responce, try again."
menu()
for line in temp1:
if searchcriteria in line:
print line
errorMessage()
# USER DID NOT PICK CREATE OR SEARCH
def errorMessage():
print ("Incorrect Answer")
exit()
menu()
問題についてより明確にしてください:あなたが何しようとしている、あなたの代わりに何が起こるか、起こるために何を期待していますか? –
あなたはエントリーを作成していますか? またはエントリーを検索していますか?1 これは私達が作成する場所です 人の姓ですか? SHA トレースバック(最新の呼び出しの最後): ファイル "C:\ユーザーは、学校LAB 4-1の\ addressbook.py \" メニュー() ファイル「Cに、ライン84を:学校のLAB 4 \ \ユーザー-1 \ addressbook.py "、行14、メニュー内 append_data(index、size、count) append_dataのファイル" C:\ Users \ SChool LAB 4-1 \ addressbook.py "、行34、 姓] = raw_input( "人の姓は何ですか?") NameError:グローバル名 'lastname'は定義されていません >>> –
私はこのコミュニティに初めての反応の残虐行為には申し訳ありません。 –