0

I am doing a project for a computer science NEA and I need to solve this problem, the problem being that global variables just won't work in the function. I'm probably being stupid but I'm not the best python programmer and it is really bugging me, it is a bunch of 'if' loops due to it being a selection algorithm, all help appreciated thanks! The main issue is that it always adds 1 to 'c' no matter if i write something like 'warlike' where it should add 1 to 'd' The bit of the code where issues are being had is down below or above, im not sure how this website works much, but the code is somewhere close to this message, looking forward to hearing from you all!

    c = int(0)
    csh = int(0)
    d = int(0)
    dsh = int(0)
    e = int(0)
    f = int(0)
    fsh = int(0)
    g = int(0)
    gsh = int(0)
    a = int(0)
    ash = int(0)
    b = int(0)

    def add_item(event=1):
      global list1
      global c
      global csh
      global d
      global dsh
      global e
      global f
      global fsh
      global g
      global gsh
      global a
      global ash
      global b
      if entry1.get() != "":
          listbox.insert(tk.END, entry1.get())
          #entry1.set("")
      if entry1 == "happy" or "cheerful" or "sunny" or "daytime":
        c = c + 1
      elif entry1 == "seldom" or "quaint" or "surly" or "discontent":
        csh = csh + 1
      elif entry1 == "triumphant" or "warlike" or "symphony" or "rejoice":
        d = d + 1
      elif entry1 == "love" or "god" or "heart" or "pop":
        dsh = dsh + 1
      elif entry1 == "joy" or "pleasure" or "laughter" or "delight":
        e = e + 1
      elif entry1 == "calm" or "complaisance" or "relaxing" or "soothing":
        f = f + 1
      elif entry1 == "relief" or "conquering" or "completeness" or "battle":
        fsh = fsh + 1
      elif entry1 == "rustic" or "idyllic" or "satisfying" or "tender":
        g = g + 1
      elif entry1 == "death" or "grave" or "dark" or "doom":
        gsh = gsh + 1
      elif entry1 == "innocence" or "affair" or "beloving" or "parting":
        a = a + 1
      elif entry1 == "cool" or "wild" or "bewildering" or "magestic":
        ash = ash + 1
      elif entry1 == "night" or "party" or "starry" or "galactic":
        b = b + 1
      entry1.delete(0, tk.END)
      list1.append(entry1.get())

0 Answers0