0

I am new in python programming. I am facing problem on elifstatement. I can't find out the syntax error. My code given below.

for num in range(1,31):  

       if (num%5 == 0) or (num%3 == 0):  

          if (num%3 == 0):
             print ("beep")
             elif (num%5 == 0):
                print ("boop")
             else:
                print ("beepboop")

       else:          

      print (num)
3
  • Is this how you intended the code? Commented Apr 11, 2017 at 10:22
  • Yes.. This is my full code .. Commented Apr 11, 2017 at 10:25
  • I suspect this won't do what you want even when you correct the indentation. You can never print "beepboop" (which you probably want to print for 15 and 30) because in both cases num%3 will be zero, so you will have already printed "beep". Once you know at least one of the two is zero, try checking if the other is non-zero, Commented Apr 11, 2017 at 10:29

1 Answer 1

2

Wrong indent

for num in range(1, 31):
    if (num % 5 == 0) or (num % 3 == 0):
        if num % 3 == 0:
            print("beep")
        elif num % 5 == 0:
            print("boop")
        else:
            print("beepboop")
    else:
        print(num)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.