2016-09-11 9 views
0

私のコードでは、数字8桁のユーザー入力を検証し、テキストファイルに格納されています。私はバリデーションを別にする前に、8桁の数字を受け入れることにしました。なぜなら、私はそれらを組み合わせると文法エラーが出てくるからです。 (5行目)ジョイント時にユーザ入力を検証する?

GTIN='' 
items=[] 
while len(items) < int(itemsneeded): 
      GTIN=(input('Please enter all GTIN-8 for all items')) 
      if GTIN.isdigit() and len(GTIN)==8 and in open('read_it.txt').read(): 
       Num0=int(GTIN[0])*3 
       Num1=int(GTIN[1]) 
       Num2=int(GTIN[2])*3 
       Num3=int(GTIN[3]) 
       Num4=int(GTIN[4])*3 
       Num5=int(GTIN[5]) 
       Num6=int(GTIN[6])*3 
       Num7=int(GTIN[7]) 
       total2=(Num0+Num1+Num2+Num3+Num4+Num5+Num6+Num7) 
       if total2 % 10 == 0: 
        print(GTIN) 
       items.append(GTIN) 
      else: 
       print("Product Not Found") 
print(items) 
+0

'とオープン( 'read_it.txt')を配置する必要があります。 read() 'は、' open( 'read_it.txt')にあるべきものが見つからないように見えます。 'True' – Railslide

答えて

0

代わり

if GTIN.isdigit() and len(GTIN)==8 and in open('read_it.txt').read(): 

の使用は

if GTIN.isdigit() and len(GTIN)==8 and GTIN in open('read_it.txt').read(): 

あなたは

...GTIN in open('read_it.txt').read() 
+0

何か愚かな間違い、大変ありがとう、ありがとう:)(私は5分待たなければならない) –