-3

Why does this print all Notes, not just notes 1,3,6,8 and 10?

Notes = ["C",["Db","C#"],"D",["Eb","D#"],"E","F",["Gb","F#"],"G",["Ab","G#"],"A",["Bb","A#"],"B"]

for noteNumb in range (0,len(Notes)):
    if noteNumb == 1 or 3 or 6 or 8 or 10:
        print(noteNumb)
JeffUK
  • 4,107
  • 2
  • 20
  • 34
  • `if noteNumb==1 or 3 or 6 or 8 or 10` is not the right way to test for multiple values. See this answer for the correct way https://stackoverflow.com/a/15112149/494134 – John Gordon Nov 17 '20 at 15:56
  • Can you post the full traceback? – Ray Nov 17 '20 at 15:57
  • you should try debugging the code, see what state the various variables are in the cases when it breaks, and compare it to the state of those variables when it doesn't break; you'll very quickly see the problem! At the very least identify which line of code is erroring. – JeffUK Nov 17 '20 at 15:57
  • Please also look at how to write a Minimal Reproducible Example, as it is stands your code has lots of stuff in that's not relevant to your problem, and doesn't run as you've missed stuff out! https://stackoverflow.com/help/minimal-reproducible-example – JeffUK Nov 17 '20 at 15:58
  • Removing a lot of code that I cannot run, most of it works. Are you sure you get the error? – Ray Nov 17 '20 at 15:59
  • Please supply the expected [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Show where the intermediate results differ from what you expected. We should be able to copy and paste a contiguous block of your code, execute that file, and reproduce your problem along with tracing output for the problem points. This lets us test our suggestions against your test data and desired output. Your posted code fails to run in several respects. We need the full error message. Reduce your posted code so that you're asking *one* question, not several errors. – Prune Nov 17 '20 at 16:00
  • You're making us guess where the error is happening. Please update the question to include the full error traceback message. – John Gordon Nov 17 '20 at 16:01
  • @JeffUK Yeah I do understand that, but in this case, I wasn't 100% sure _what_ was relevant to my problem - thanks for your reply though! – louis george Nov 17 '20 at 16:11
  • @louisgeorge that's where the debugger comes in! – JeffUK Nov 17 '20 at 16:13

1 Answers1

0

The problem is in the line if noteNumb==1 or 3 or 6 or 8 or 10:

(1 or 3 or 6 or 8 or 10) will always return 1

if noteNumb in [1,3,6,8,10]: will solve your immediate problem

if type(note) is list:
    note=random.choice(note) 

Will solve the problem more generically.

JeffUK
  • 4,107
  • 2
  • 20
  • 34