0

i have been having this issue for about a month and i've tried solving it many times, the solution i'm going to post worked for 2 days before deciding not to work for some reason even though it is completely correct syntactically, clearly there are issues can anyone help me please

it always calls 'c' for some reason even when i type 'love' it still calls c which i've very clearly told it not to do

i have been having this issue for about a month and i've tried solving it many times, the solution i'm going to post worked for 2 days before deciding not to work for some reason even though it is completely correct syntactically, clearly there are issues can anyone help me please

it always calls 'c' for some reason even when i type 'love' it still calls c which i've very clearly told it not to do

c = int(0)
csharp = int(0)
d = int(0)
dsharp = int(0)
e = int(0)
f = int(0)
fsharp = int(0)
g = int(0)
gsharp = int(0)
a = int(0)
asharp = int(0)
b = int(0)

def add_item(event=1):
  global list1
  global c
  global csharp
  global d
  global dsharp
  global e
  global f
  global fsharp
  global g
  global gsharp
  global a
  global asharp
  global b

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

1 Answers1

0

The issue with your code is that the if statement is checking if the entire list1 variable is equal to one of the lists of words when it should be checking if the word entered in the entry1 widget is in one of those lists.

One way to fix this is to change the if statement to use the in keyword to check if the word entered in entry1 is in one of the lists. For example:

if entry1.get() in ["happy", "cheerful", "sunny", "daytime"]:
    c = c + 1

And so on for all the other elif statements.

It would be better to use a dict or a map to hold all the words and then the corresponding note. This would make the code more readable and efficient.

note_map = {
"happy": "c",
"cheerful": "c",
"sunny": "c",
"daytime": "c",
"seldom": "c#",
"quaint": "c#",
"surly": "c#",
"discontent": "c#",
...

} note = note_map.get(entry1.get(), "") if note: note_variable = note + " + 1" exec(note_variable)

This way you can add as many words as you want and map them to the corresponding notes.

Saquib
  • 3
  • 3