1
n=range(101)
if n%2==0:
     print("weird")
if range(2,6):
     print("not weird")
if range(6,21):
     print("weird")
if n>20:
     print("not weird")
else :
     print("weird")

Given an integer, , perform the following conditional actions:

If is odd, print Weird If is even and in the inclusive range of 2 to 5, print Not Weird If is even and in the inclusive range of 6 to 20 , print Weird If is even and greater than 20, print Not Weird

2
  • Please include the error that you're getting Commented Aug 30, 2018 at 14:43
  • it's weird indeed Commented Aug 30, 2018 at 15:08

1 Answer 1

1

You should use a for loop to iterate through the range generator, and you should use the in operator to test if n is in a range, and if you mean to print only upon the first matching rule for each number, you should use elif statements instead of if for the conditions that follows the first. You might also want to print the number itself so that you know which numbers are "weird" and which are "not weird":

for n in range(101):
    print(n, end=' ')
    if n%2==0:
         print("weird")
    elif n in range(2,6):
         print("not weird")
    elif n in range(6,21):
         print("weird")
    elif n>20:
         print("not weird")
    else:
         print("weird")
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.