0

これが私のコードです。すべてを「印刷」するように設定すると、コードは機能しましたが、件名、トピック、および質問/回答を選択すると、「リターン」でプログラムが終了します。私はこのプログラムをフラッシュ カードの質問と回答に入力し、次に主題を選択し、次にトピックを選択して、質問のみ、回答、または両方を表示するかどうかを選択できるように作成しました。各リストの最後に「None」という単語が表示されることに気付きました。「print」を「return」に置き換えてこれを修正しようとしましたが、さらに多くの問題が発生しました。すべきです。

コードは以下です

--イーサン、13歳

import sys
subjects = ["History", "Science"]
topics_science = ["Light", "X-mas Exam Review"]
topics_history = ["Italian Renaissance"]
science_xmasreview = ["Q. What do we use to catogorize a habitat?", \
"A. Damp or Dry, Hot or Cold, Windy or Calm, Dim or Bright.", \
"Q. What is something that only eats plants?", \
"A. Herbivore", \
"Q. What are the properties of oxygen?"]

science_light = [
"Q. What is an object the gives out light?", \
"A. Light source", \
"Q. What is the speed of light?", \
"A. 300 million meters per second.", \
"Q. What does transparent mean?", \
"A. Light can pass completely through a transparent material."]

history_renaissance = [
"Q. What did Lorenzo do differently from Cosimo?", \
"A. Lorenzo made no effort to conceal his power", \
"Q. Why did the Pope want Lorenzo dead?", \
"A. Because the Pope wanted more power and saw Lorenzo as a threat.", \
"Q. Who did the Pazzi plot with to kill Lorenzo?", \
"A. Pope Sixtus IV"]

def qanda(x):
    print
    print "Enter 1 for just questions"
    print "Enter 2 for just answers"
    print "Enter 3 for both"
    qa = raw_input("Enter number: ")
    qa = str(qa)
    if qa == '1':
        printer(x[::2])
    elif qa == '2':
       printer(x[1::2])
    elif qa == '3':
        printer(x)
    else:
        print "Not recognized"
def newline():
    raw_input()
    print
def printer(list):
    n = 0
    l = len(list)
    print
    while n < l:
        return list[n]
        newline()
        n += 1
    while n == l:
        n += 1
def subjectchoice():
    if subject == "1":
        print
        history()
    elif subject == "2":
        print
        science()
        else:
        print 'Not recognized.'
def science():
    print topics_science
    print "Enter 1 for Light"
    print "Enter 2 for X-mas Exam Review"
    topicchoice = raw_input("Enter number: ")
    topicchoice = str(topicchoice)
    if topicchoice == "1":
        qanda(science_light)
    elif topicchoice == "2":
          qanda(science_xmasreview)
    else:
        print "Not recognized"
        sys.exit
def history():
    print topics_history
    print "Enter 1 for Italian Renaissance"
    topicchoice = raw_input("Enter number: ")
    topicchoice = str(topicchoice)
    if topicchoice == "1":
       return qanda(history_renaissance)
    else:
        print "Not recognized"
        sys.exit()
print subjects
print "Enter 1 for History"
print "Enter 2 for Science"
subject = raw_input("Enter number: ")
subject = str(subject)
subjectchoice()
4

1 に答える 1

0

これでうまくいくと思います。printer() 関数に return ステートメントは必要ありませんでした。

import sys
subjects = ["History", "Science"]
topics_science = ["Light", "X-mas Exam Review"]
topics_history = ["Italian Renaissance"]
science_xmasreview = ["Q. What do we use to catogorize a habitat?",
                      "A. Damp or Dry, Hot or Cold, Windy or Calm, Dim or Bright.",
                      "Q. What is something that only eats plants?",
                      "A. Herbivore",
                      "Q. What are the properties of oxygen?"]

science_light = [
    "Q. What is an object the gives out light?",
    "A. Light source",
    "Q. What is the speed of light?",
    "A. 300 million meters per second.",
    "Q. What does transparent mean?",
    "A. Light can pass completely through a transparent material."]

history_renaissance = [
    "Q. What did Lorenzo do differently from Cosimo?",
    "A. Lorenzo made no effort to conceal his power",
    "Q. Why did the Pope want Lorenzo dead?",
    "A. Because the Pope wanted more power and saw Lorenzo as a threat.",
    "Q. Who did the Pazzi plot with to kill Lorenzo?",
    "A. Pope Sixtus IV"]

def printer(list):
    n = 0
    l = len(list)
    print
    while n < l:
        print list[n]  # <-- Changed this from a return to a print statement
        newline()
        n += 1
    while n == l:
        n += 1

def qanda(x):
    print
    print "Enter 1 for just questions"
    print "Enter 2 for just answers"
    print "Enter 3 for both"
    qa = raw_input("Enter number: ")
    qa = str(qa)
    if qa == '1':
        printer(x[::2])
    elif qa == '2':
        printer(x[1::2])
    elif qa == '3':
        printer(x)
    else:
        print "Not recognized"

def newline():
    raw_input()
    print



def subjectchoice():
    if subject == "1":
        print
        history()
    elif subject == "2":
        print
        science()
    else:
        print 'Not recognized.'
def science():
    print topics_science
    print "Enter 1 for Light"
    print "Enter 2 for X-mas Exam Review"
    topicchoice = raw_input("Enter number: ")
    topicchoice = str(topicchoice)
    if topicchoice == "1":
        qanda(science_light)
    elif topicchoice == "2":
        qanda(science_xmasreview)
    else:
        print "Not recognized"
        sys.exit
def history():
    print topics_history
    print "Enter 1 for Italian Renaissance"
    topicchoice = raw_input("Enter number: ")
    topicchoice = str(topicchoice)
    if topicchoice == "1":
        return qanda(history_renaissance)
    else:
        print "Not recognized"
        sys.exit()
print subjects
print "Enter 1 for History"
print "Enter 2 for Science"
subject = raw_input("Enter number: ")
subject = str(subject)
subjectchoice()
于 2013-03-17T20:15:25.117 に答える