from untitled5 import Question
choose1=[
"有沒有想我啊?\n (a)當然摟 想死你了\n (b)怎麼可能 我已經忘記你勒\n",
]
questions = [
Question(choose1[0],"a"),
]
def test(questions):
for question in questions:
answer = input(question.description)
if answer == question.answer:
print("太棒了","看你疑惑的眼神,我還以為你忘了我(","給予","一個大大的擁抱")
if answer != question.answer:
print("琳達:真沒想到你竟然忘了我,我真的好難過")
print("琳達跑走了")
class Question:
def __init__(self,description,answer):
self.description=description
self.answer=answer
根據影片做了個問答程式 有小改過 但run的時候什麼都沒發生 很好奇怎麼沒跑出題目
請大神解惑
因為少了一列test(questions)
加入後大概像這樣
...
questions = [
Question(choose1[0],"a"),
]
test(questions)
...
test(questions)
必須至於def test(questions):
後
像這樣:
class Question:
def __init__(self,description,answer):
self.description=description
self.answer=answer
choose1=[
"有沒有想我啊?\n (a)當然摟 想死你了\n (b)怎麼可能 我已經忘記你勒\n",
]
questions = [
Question(choose1[0],"a"),
]
# test(questions) # 如果在這裡呼叫函式的話,會應為函式尚未被宣告而出現NameError錯誤。
def test(questions):
for question in questions:
answer = input(question.description)
if answer == question.answer:
print("太棒了","看你疑惑的眼神,我還以為你忘了我(","給予","一個大大的擁抱")
if answer != question.answer:
print("琳達:真沒想到你竟然忘了我,我真的好難過")
print("琳達跑走了")
test(questions) # 加在這裡!
恭喜你自己解決一個問題了
對 我後來有發現加在最後面
感謝幫助 之前因為任務沒完成沒法回復