2016-05-29 5 views
-1

こんにちは、私はここにPythonプログラムを書こうとしています。私がしようとしているのは、ユーザーに6桁の数字を入力させることです.6桁でない数字を入力すると、6桁の数字を入力する必要があるというエラーメッセージが表示されます。私はdef example_check_message(m):と呼ばれる関数を持っていますが、数字は6桁でなければならず、ユーザーが数字を入力するとdef example_get_number():という関数があります。数字の関数はdef example_check_message(m)関数を呼び出す必要があります。ハプニング。私はそれに近いと知っているが、どこが間違っているのか分からない。関数の入力を読み込むPythonプログラム

def example_check_message(m): 

    b = False, 
    try: 
     if m == int >= '100000' and '<1000000': 
      b = True 
    except: 
     print 'You must enter a number' 

    return b 


def example_get_number(): 
    example_check_message(1) 
    b = False 

     while b == False: 
      num = raw_input('Please enter a 6 digit number:') 

      if example_check_message(num) == True: 
       b = True 
       continue 
      value = int(num) 
      return value 


if __name__ == '__main__': 
    example_check_message(1) 
    example_get_number() 
+1

"m == int> = '100000'と '<1000000':"とは何でしょうか?このコード部分には、少なくとも3つの異なるタイプのエラーがあります。おそらく '1e6 <= int(m)<1e7' – lejlot

+0

を意味していたのですが、' while b == False'ブロックのインデントは必ずエラーを生成します。 –

+0

'while'ループは何度も反復することはありません。無意味になります。 – interjay

答えて

0

私はあなたが何かしたいと思う:

def example_check_message(m): 
    try: 
     m = int(m) 
     if m >= 100000 and m < 1000000: 
      return m # <- return something useful! 
    except: 
     print 'You must enter a number' 
    return False 

をしかし、エラーが、この中にある - 病気のどこにいくつかのヒントを与えます。このままでは機能しないはずですが、まだ作業や学習が必要です。

def example_get_number(): 
    example_check_message(1) 
    b = False 

    while b == False: # not b is the right way here 
     num = raw_input('Please enter a 6 digit number:') 

     if example_check_message(num) == True: # This could be simpler 
      b = True 
      continue # <- no need to continue here, just return 
     value = int(num) # <- do this already on the input! 
     return value 
+0

助けていただきありがとうございます、私は私が私よりずっと近くにいると思っていました。私はちょうど学んでいるが、それは悪夢のように見えて、私はそれについて良いチュートリアルを見つけることが難しいと思っている。 – user6396577

+0

私はあなたがチュートリアルを必要としないことをお勧めします - あなたはいくつかの永続性が必要です。行ごとに、それぞれが何をしているのか考えてみてください。あなたがまだ学習している場合は、自然言語の段落を書くのと同じ方法で関数を書くことができるまでにはしばらく時間がかかるでしょう。 – domoarrigato

+0

お返事ありがとうございます。 – user6396577

関連する問題