2017-11-26 4 views
-1

このためにタイプエラーが発生しています。私は装飾的な機能を試しています。すべてのヘルプは装飾機能でタイプエラーが発生し続ける

def primer(func): 
    def primes(n): 
     print (n) 
     return None 





@primer 
def find_prime(n): 
    while True: 
     count = 2 
     if (count == n): 
      z = ("PRIME") 
      return z 
     elif (n % count == 0): 
      z = n/count 
      return z 
     else: 
      count += 1 
      continue 

prime = find_prime() 
prime(10) 
+0

ヒントを高く評価している:デコレータとあなたはまだエラーを取得するかどうかを確認するために関連しているものを削除します。 ヒント2:そのエラーで書き込まれた内容を読みます。 ヒント3:このようなアプローチでは、「Boo boo。HELP!」あなたは遠くに行っていない。インターネットに関する研究。否定投票で驚かないでください。 –

答えて

0
def primer(func): 
    def primes(n): 
     print(n) 
     #return None: dont know why this is here, you could do without it 
    return primes 
    #The nontype error is occuring because your code is returning none 
    #so to fix that all you have to do is return the inner function 


@primer 
def find_prime(n): 
    while True: 
     count = 2 
     if (count == n): 
      z = ("PRIME") 
      return z 
     elif (n % count == 0): 
      z = n/count 
      return z 
     else: 
      count += 1 
      continue 

prime = find_prime 
# if you want to turn a function into a variable you have to make sure it's 
# callable, which means no parantheses around it 

prime(15) # then you can call it 
+0

ありがとうございました!私はそれらのすべての間違いを作るためのダミーのように感じる。 – Pushk1n

関連する問題