A
A
Alex Moon2018-03-07 22:59:39
Python
Alex Moon, 2018-03-07 22:59:39

Neuronnik in python 3 iterates over all options, but you need one, how to do it?

I have a neuron that should determine the characteristics of a word, that is, whether it is neutral in use, I ran into such a problem, the neuron goes through the entire dictionary and displays the answer to everyone what it is, how can I fix it?
code:
lq.py

def write_a(name, data):
    f = open(name, 'a+')
    f.write(data)
    f.close()
class brain:
  def __init__(self, config, msgs):
    self.configname = config
    self.msgsn = msgs
    f = open(config)
    fs = open(msgs)
    self.msgs = fs.read().strip().replace("\n", "").split('-')
    fs.close()
    self.conf = f.read().strip().replace("\n", "").split("-")
    f.close()

  def check_rules(self):
    fs = open(self.msgsn)
    self.msgs = fs.read().strip().replace("\n", "").split('-')
    fs.close()

  def check_msgs(self):
    f = open(self.configname)
    self.conf = f.read().strip().replace("\n", "").split("-")
    f.close()

  def get_rules(self):
    f = open(self.configname)
    self.conf = f.read().strip().replace("\n", "").split("-")
    f.close()
    return self.conf

  def add_rule(self, rulename, parametr):
    write_a(self.configname, "-\n"+rulename+'-'+parametr)

code from network.py
import lq
s = lq.brain('net.ns', 'ms.ns')

while True:
  msg = input('Скажи: ').lower()
  s.check_rules()
  s.check_msgs()
  if s.msgs.count(msg) == 0:
    print("Я пока незнаю такого слова")
    do_s = input('Это слово хорошее? y/n: ')
    if do_s == 'y':
      file = open("ms.ns", 'a+')
      file.write("-\n"+msg+"-хорошо")
      file.close()
    else:
      file = open("ms.ns", 'a+')
      file.write("-\n"+msg+"-плохо")
      file.close()
  else:
    for i in s.msgs:
      if i == msg:
        #print('Классно я помню')
        mm = True
        for ii in s.msgs:
          if mm:
            if i == msg:
              mm = False
              continue
          else:
            if i == msg:
              if ii == 'хорошо':
                print("Нейтральное")
              elif ii == 'плохо':
                print('не Нейтральное')

options:
кот-хорошо-
человек-хорошо-
сэт-хорошо-
сэр-хорошо-
кэт-хорошо-
кт-хорошо

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question