0

この課題について助けが必要です:

**4 つのグローバル変数を使用

foundCount  = 0
searchCount = 0
names = [ "Mary", "Liz", "Miles", "Bob", "Fred"]
numbers = [ 4, 17, 19]
def find(item):
    ....
def result():
    ....

2 つの関数の本体のコードを記述します。

find()

名前のグローバルリストで検索する単一のパラメーターを受け取り、そこに見つからない場合は、数値のリストを検索します。

アイテムが見つかったかどうかにかかわらず、常に searchCount をインクリメントします

アイテムが見つかった場合は、foundCount をインクリメントし、必要に応じて "Found in Names" または "Found in Numbers" を出力します。

アイテムが見つからない場合は「見つかりません」と表示されます

results() これにはパラメーターがありません。検索数の要約を出力します: 例: "Total Searches: 6, Found items: 4, Not found: 2"**

サンプルラン

**======= Loading Program =======
>>> find("mary")
 Not found
>>> find("Mary")
 Found in names
>>> find(0)
 Not found
>>> find(19)
 Found in numbers
>>> results()
  ***** Search Results *****
 Total searches:  4
 Total matches :  2
 Total not found: 2**

私がこれまでに行ったことは次のとおりです。

**

foundCount  = 0
searchCount = 0
names = [ "Mary", "Liz", "Miles", "Bob", "Fred"]
numbers = [ 4, 17, 19]
def find(item):
    global foundcount
    if item == "Mary":
      printNow("Found in names")
    elif item == "Liz":
      printNow("Found in names")
    elif item == "Miles":
      printNow("Found in names")
    elif item == "Bob":
      printNow("Found in names")
    elif item == "Fred":
      printNow("Found in names")
    elif item == "4":
      printNow("Found in numbers")
    elif item == "17":
      printNow("Found in numbers")
    elif item == "19":
      printNow("Found in numbers")
    else: printNow("Not Found")

def result():

**

def result() 関数の助けが必要なので、この課題を 3 日で終わらせて、数学の試験の勉強をすることができます.明日が期限なので、この課題をするのに助けが必要です :(....

4

1 に答える 1

1

in次の演算子を使用します。

def find(item):
    global foundcount

    if item in names:
        foundCount += 1
        printNow("Found in names")
    elif item in numbers:
        foundCount += 1
        printNow("Found in numbers")
    else:
        printNow("Not Found")

に関しては、次の関数resultを使用できます。print

print('Found Items:', foundCount)
于 2013-04-04T01:57:03.947 に答える